Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Becoming Patient in Writing Programs (symbo1ics.com)
5 points by reikonomusha on Sept 9, 2013 | hide | past | favorite | 1 comment


Late reply here because I just tried submitting this link myself :)

What got me interested was how another language which used consistent data structure for its syntax would look here in comparison.

So here is my stab at it using Rebol...

  ; Array Access
  pick x i
  x/:i       ; PATH! alternative
  
  ; Function call
  f x
  
  ; Arithmetic
  (a / 2) + (b * c) + square-root d
  
  ; Conditional Branching (part 1)
  either a = b [x] [y]
Rebol doesn't have else if so this looks a little clumsy:

  ; Conditional Branching (part 2)
  either a == b [
      doThis a
      x
  ][
      either c == d [
          doThat b
          y
      ][z]
  ]
And it doesn't have a cond either. However its easy to add one :)

  cond: func [cond-list] [
      foreach line cond-list [
          c: compose line
          if true? c/1 [break/return do c/2]
      ]
  ]
  
  cond [
      [(a = b) [doThis a x]]
      [(c = d) [doThat b y]]
      [true    [z]]
  ]




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: