Lately I've been reading parts of this funny document: (The Master Foo section is
especially funny: )

Anyway I thought that perhaps it would be possible to somehow bypass the
need for an actual physical file as input to these UNIX commands and one of
the out examples in the reference does just that:

Here the result of a little fiddling:

(class +Cmd)

(dm exe> (Str AsStr . @)
   (pipe (out (rest) (prin Str)) (till NIL AsStr)) )

#(println (md5sum> '+Cmd "hej"))
(dm md5sum> (Str)
   (car (mapcar pack (split (exe> This Str NIL 'md5sum) " "))))

(dm sed> (Cmd Str)
   (exe> This Str T 'sed Cmd))

#(println (ssub> '+Cmd "hej" "pej" "hej pa dig hej"))
(dm ssub> (Search Replace Str)
   (sed> This (pack "s/" Search "/" Replace "/g") Str))

(dm awk> (Cmd Str)
   (exe> This Str T 'awk (pack "{ " Cmd " }")))

#(println (match> '+Cmd "apa" "apa hej pa dig"))
(dm match> (Search Str)
   (<> 0 (any (awk> This (pack "print match($0, /" Search "/)") Str))) )

#(println (gsub> '+Cmd "hej" "pej" "apa hej pa dig hej"))
(dm gsub> (Search Replace Str)
   (awk> This (pack "gsub(/" Search "/, \"" Replace "\"); print")

What is the point of this one might wonder, why not just call an external
"modern" Python/Ruby/PHP/Insert your favorite instead, like this?:

(dm php> (Script . @)
   (in (append (list "php" (pack Script ".php")) (rest)) (till)))

In most cases it won't matter probably, invoking sed, awk et al should
however entail a lot less overhead for a busy application.

Reply via email to