RCHQ9+/NetRexx: Difference between revisions

From Rosetta Code
Content added Content deleted
m (Link to other RHQ9+ implementations)
m (fix hello message)
Line 14: Line 14:
if cc \= '' then do
if cc \= '' then do
select case cc
select case cc
when 'h' then say 'hello, world'
when 'h' then say 'Hello, world!'
when 'q' then say quine
when 'q' then say quine
when '9' then ninetyNineBottles()
when '9' then ninetyNineBottles()

Revision as of 02:57, 1 July 2013

RCHQ9+/NetRexx is an implementation of HQ9+. Other implementations of HQ9+.
RCHQ9+/NetRexx is part of RCHQ9+. You may find other members of RCHQ9+ at Category:RCHQ9+.

<lang NetRexx>/* NetRexx */ options replace format comments java crossref symbols nobinary

runSample(arg) return

-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method interpretHCQ9p(code, accumulator = 0) public static

 quine = code
 loop for code.length
   parse code cc +1 code
   cc = cc.lower
   if cc \=  then do
     select case cc
       when 'h' then say 'Hello, world!'
       when 'q' then say quine
       when '9' then ninetyNineBottles()
       when '+' then accumulator = accumulator + 1
       otherwise     nop
       end
     end
   end
 return accumulator

-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method ninetyNineBottles() public static

 bottleCount = bottles(99)
 loop bc = 99 to 1 by -1
   say bottleCount 'on the wall'
   say bottleCount
   say 'Take one down, pass it around'
   bottleCount = bottles(bc - 1)
   say bottleCount 'on the wall'
   say
   end bc
 return

method bottles(nb) private static

 select case nb
   when 0 then bm = 'No more bottles'
   when 1 then bm = 'One bottle'
   otherwise   bm = nb 'bottles'
   end
 return bm 'of beer'

-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method runSample(arg) public static

 parse arg code
 say 'HQ9+ Accumulator =' interpretHCQ9p(code)
 return

</lang>