How REBOL saved the FilmCamp screening

As the continuation of the unwritten story of "How UNIX script saved the Barcamp" ( http://barcamp.org/BarCampSingapore4 ) here is another micro contribution, now to http://2010.filmcamp.sg/

We were screening short an long films during the event. We queried the length of all the clips but we wanted to inform the audience about the cumulative start time of every video.

So we had a list of time offsets on paper and a start time, like this:

start time 12:20
film1 .... 1:36
film2 .... 0:42
film3 .... 1:06:14
...

"Tom, can you add time values fast together? ... or how can we calculate these?" -- asked Adrian (aka s1ash)

"Well... REBOL can!" -- I answered

>> 12:20 + 0:1:36
== 12:21:36
>> 12:20 + 0:1:36 + 0:0:42
== 12:22:18
...

So we simply did the calculation by expanding the number of operands just to make sure the job gets done. Next I showed how to do it more programmatically, taking out the repetition of the addition operator.

I tried to do it in a nice functional way, but the map function has been renamed to map-each, which I forgot on the spot, so I went back to the "PHP" way 1st:

>> t0: 12:20   foreach t [0:1:36 0:0:42 1:6:14] [print t0: t0 + t]12:21:3612:22:1813:28:32

Later, during lunch, I took the laptop on the table and gave the more functional version another try:

>> t0: 12:20 print map-each t [0:1:36 0:0:42 1:6:14] [t0: t0 + t]
12:21:36 12:22:18 13:28:32

On the way back from lunch, after I showed how REBOL deals with DSLs (Domain Specific Languages) or Dialects as they call it, and how can it handle JPG/PNG out of the box as well as SHA1 / MD5 checksums and RSA encryption, we held a little guessing session about the size of the "REBOL install package". Ruiwen had a half silent, half sentence about the unit should be kilobytes but he considered the idea ridiculous by himself and also made guesses on the megabyte range. Adrian's first guess was 10MB. I was shaking my head with wide open eyes which made him modify the bet to 15M! I told them to try to aim lower, so Ruiwen was daring to say 4MB. I didn't want to cause heart attacks directly, so I was hinting as "below 1M".

The shock didn't let them guess any further, so I had to tell the actual value:

  • 360kiloByte.
  • 1 executable file
  • No installation, just drop it onto your $PATH or %PATH% -- because it's cross platform!
  • with built in help and  source "decompiler" even for some builtin words
  • network protocols (HTTP,FTP,POP,IMAP,SMTP,FINGER,WHOIS,DNS,SOCKS4/5)
  • DSL parser
  • direct recognition of URLs, email addresses, dates, times, money, IP address or RGB codes...

But back to the original problem which still sucks, because it's not completely functional... I want something like what's default in LISP

(+ 1 2 3 4 5)

Well... the next generation REBOL gives us an APPLY function which does something like this:

>> apply :+ [12:20 0:1:36 0:0:42 1:6:14]                          
== 12:21:36

Hmm... almost good, but

  1. we can't see the intermediary results :/
  2. it has just summed the 1st 2 elements :?

Okay... I should go back and learn more OOOOR think a little bit more about why do we actually need to solve this in a more functional manner at all?... :)

 

986 views and 2 responses

  • Dec 15 2011, 1:03 PM
    rgchris responded:
    Timely as ever, but couldn't resist:

    alt-apply: func [action [any-function!] block [block!] /local][
    local: pick block 1
    block: copy next block
    while [not tail? block][
    insert insert block :action :local
    set [local block] do/next block
    ]
    local
    ]

    Usage:

    alt-apply :add [1 2 3 4]
    alt-apply :+ [12:20 0:1:36 0:0:42 1:6:14]
    alt-apply :join ["a" "b" "c"]

  • Dec 15 2011, 1:09 PM
    rgchris responded:
    Only really useful for two-arg functions though. And will loop on one...