After taking a look at the Forth and Factor programing languages for the
first time a few days ago, I started making my own stack-based language
which fully integrates with R6RS Scheme.  It's still embryonic and
subject to change.

For example, this Factor example from [1]:

        "/etc/passwd" ascii file-lines
        [ "#" head? not ] filter
        [ ":" split first ] map

Can be done in my language like:

  (import (xitomatl stack-lang))

  (define-λS (file-lines file-name)
    (import (xitomatl ports))
    (call-with-input-file file-name get-lines-all))

  (define-λS (head? str char)
    (and (positive? (string-length str))
         (char=? (string-ref str 0) char)))

  (define-λS (split str char)
    (import (xitomatl strings))
    (string-split str (string char)))

  (define-λS (first l) (car l))

  (S "/etc/passwd" file-lines
     (Q #\# head? not) filter
     (Q #\: split first) map
     print)

PRINTS=>

("root" "daemon" "bin" "sys" "sync" "games" "man" "lp"
 "mail" "news" "uucp" "proxy" "www-data" "backup" "list"
 "irc" "gnats" "nobody" "dhcp" "syslog" "klog" "messagebus"
 "avahi-autoipd" "avahi" "cupsys" "haldaemon" "hplip" "gdm"
 "d" "ftp" "sshd" "ntp" "Slmodemd" "libuuid" "pulse"
 "polkituser" "landscape" "saned")

        
[1] http://concatenative.org/wiki/view/Pipeline%20style

-- 
: Derick
----------------------------------------------------------------

Reply via email to