On 2006-02-02, Matthew Astley wrote:
> I'm most interested in
>
>   How to do <foo> in Lisp, where <foo> is defined in other language.
>
> e.g. How do I write a heredoc in Lisp?

The shell uses heredocs to direct text from your script into a
program.  Lisp uses QUOTE for that.  If your function insists on
reading an actual file handle, use WITH-INPUT-FROM-STRING.

Perl uses heredocs as a fancy form of quoting.  Lisp would use QUOTE,
BACKQUOTE, or double-quote (") for that.

> It has been variously suggested (on cliki) that I don't need to,
> could do it easily, or might find it rather tricky.  I haven't tried
> yet, but would appreciate advice on where (not) to start.

What kind of syntax do you want?  If you want

    (foo <<EOF)
foo reads this text
as its standard-input
EOF

or

    (foo <<EOF)
foo's first argument
is this text
as a string
EOF

then I think you will find that pretty tricky, not to mention ugly and
un-Lispy.  (I, for one, wouldn't know where to begin[1], and moreover
wouldn't *want* to begin.  :)  But if you would settle for

    (with-input-from-string (stream 
"foo reads this text
as its input")
      (foo stream))

or

    (foo "foo's first argument
is this text
as a string")

then you already have it.

In general, you cannot answer

  How do I do <foo> in Lisp, where <foo> is defined in another language.

in a general way.  It depends on <foo>, and the other language (and
the patience and free time of you and those answering, of course ;).

> This is a comparison of language idioms.  Discussion can lay bare
> one language's kludge that gets around a shortcoming another
> language doesn't have.  Hacking can import those other things that
> are actually really neat.

I think you'll have to ask specific questions.  Your question defines
quite a large state space.

My two favorite languages (Lisp and Perl) both have their quirks, but
I don't deliberately try to spend a lot of time thinking in the
abstract about how to transform one language's idioms into another.  I
try to think about good ways to solve a problem, and how I would
express it my current program.  I'll certainly admit, though, that
sometimes one language can yield a technique that also works in the
other language, and which you might not have thought of if you didn't
know the first one.  I've used more Perl closures writing slimpl.pm
than I ever have before, for example.  (Just by the way, people that
want to see some good (practical) Lisp could do worse than reading
slime.el and/or swank.lisp.  Those slime guys write good code.  But I
digress.)

-- Larry


[1] Okay, I lied: I'd begin by learning more about the readtable.  But
still, ick.


_______________________________________________
Gardeners mailing list
[email protected]
http://www.lispniks.com/mailman/listinfo/gardeners

Reply via email to