Paste: proposition for rebol modules

Author: jankoM / middayc
Mode: rebol
Date: Wed, 9 Dec 2009 22:12:05
Plain Text |
; proposition for having MODULES made in a way to enable 
; usage of short words. 
; exported words in listed modules would "overshadow" the 
; other words (if any are the same) just for the 
; block passed in

; like this

make-report: func [ data ] [
  with-modules [ haru-pdf ] [
    p: new-page
    f: font "arial" 12
    goto p 100 100
    print p f data/title newline
    row p f [ "item" "qty" "price" ]
    save p %file.pdf
  ]
]
   
; instead of  (erlang has this I think)

make-report: func [ data ] [
    p: haru-pdf/new-page
    f: haru-pdf/font "arial" 12
    haru-pdf/goto p 100 100
    haru-pdf/print p f data/title haru-pdf/newline
    haru-pdf/row p f [ "item" "qty" "price" ]
    haru-pdf/save p %file.pdf
  ]
]

; or even worse  (php had something like this)

make-report: func [ data ] [
    p: haru-pdf-new-page
    f: haru-pdf-font "arial" 12
    haru-pdf-goto p 100 100
    haru-pdf-print p f data/title haru-pdf-newline
    haru-pdf-row p f [ "item" "qty" "price" ]
    haru-pdf-save p %file.pdf
  ]
]

; we could then simply create a custom func word 
; or it could already exist natively

make-report: func-mod [ data ] [ haru-pdf ] [
  p: new-page 
  f: font "arial" 12
  goto p 100 100
  print p f data/title newline
  row p f [ "item" "qty" "price" ]
  save p %file.pdf
]

; this is not the best example because most functions 
; here "work" on p so it could be solved with relative elegance 
; by making p and object and having p/goto 100 100 etc
; but anyway, you can have modules where that will not be 
; the case by far. And I want to avoid Java's 
; LongCamesCaseNames for "modules" and functions in them 
; or in our case long-something-separated-names :)

New Annotation

Summary:
Author:
Mode:
Body: