Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language OBJ

Date:04/20/05
Author:Grigore Rosu
URL:n/a
Comments:0
Info:n/a
Score: (2.96 in 106 votes)
OBJ is an algebraic specification language.

*** OBJ version of 99 bottles of beer
*** programmer: Grigore Rosu  grosu@cs.ucsd.edu
*** creator of OBJ language: Joseph Goguen

obj STRING is sort String .
  ops We like some beer on the wall.  : -> String .
  ops Take one bottle of wall down ,  : -> String .
  ops And pass it arround the beer.   : -> String .
  ops Does anybody want bottles more? : -> String .
endo

obj LIST[X :: TRIV] is
  sort List .
  subsort Elt < List .
  op __ : List List -> List [assoc] .
endo

make CHUG is LIST [ STRING + NAT ] endm

obj BEER is protecting CHUG .
  subsort Nat < String .
  ops beers puke : Nat -> List .
  op bottle? : Nat -> String .
  var N : Nat .
  eq beers(0) = Does anybody want some more? .
  cq beers(N) = puke(N) beers(p N) if N > 0 .
  eq puke(N) = N bottle?(N) of beer on the wall , N bottle?(N) of beer.
   Take one down , pass it arround , (p N) bottle?(p N) of beer on the wall. .
  cq bottle?(N) = bottle  if N == 1 .
  cq bottle?(N) = bottles if N =/= 1 .
endo

red beers(99) .

Download Source | Write Comment

Alternative Versions

Comments

Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!

Name:

eMail:

URL:

Security Code:
  
Comment: