RCHQ9+/NetRexx: Difference between revisions

From Rosetta Code
Content added Content deleted
(Add NetRexx implementation)
 
m (Fixed syntax highlighting.)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{implementation|HQ9+}}{{collection|RCHQ9+}}
<lang NetRexx>/* NetRexx */
<syntaxhighlight lang="netrexx>/* NetRexx */
options replace format comments java crossref symbols nobinary
options replace format comments java crossref symbols nobinary


Line 13: 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()
Line 48: Line 49:
parse arg code
parse arg code
say 'HQ9+ Accumulator =' interpretHCQ9p(code)
say 'HQ9+ Accumulator =' interpretHCQ9p(code)
return
return</syntaxhighlight>
</lang>

Latest revision as of 10:17, 1 September 2022

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+.
/* 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