Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Nice.

Here are some interesting non-macro variants, first in Rebol:

  select: func [block] [
      totals: []
      parse block [
          set this word!
          'from
          set coll word!
          (totals: map-each n (get coll) [get in n this])
      ]
      totals
  ]
 
  ; then later...

  select [total from orders]

  ;; nb. `select` is a core function provided by Rebol
  ;;     so remember this example overwrites that
  ;;     (in this scope/context)  :)
  ;;
  ;;     Alternative `dialect` to strive for would be..
  ;;  
  ;;       doMap [select total from orders]

And also in Io:

  select := method(
      msg  := call argAt(0)
      this := msg name
      coll := msg next next name
  
      newMsg := message(COLL map)     // COLL just a placeholder message
      newMsg setName(coll)            // Now been changed to correct var provided
      newMsg next appendArg(this asMessage)
      call sender doMessage(newMsg)
  )

  # then later...

  select(total from orders)
Both examples work at runtime. However in Io you can also amend the AST directly.


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

Search: