Re: Is anybody's favorite computer programming language not included here?
- From: rem642b@xxxxxxxxx (Robert Maas, see http://tinyurl.com/uh3t)
- Date: Wed, 29 Jun 2005 00:07:48 -0700
> From: "John W. Krahn" <someone@xxxxxxxxxxx>
> Your "Perl script" could be written more simply as:
> #!/usr/bin/perl
> $currdate = localtime;
> print <<TEXT;
> ...
> TEXT
Ah, basically you emit a begin-end labeled multi-line string, and
insert substitution items here and there, almost like JSP or PHP with
scriptlets except you can do only variable lookups not arbitrary
calculations within a multi-line string. In Common Lisp using format
it's just about the same, except you don't have to lexically space the
lines apart in the source, you can use format directives each time you
want a new line, and you have to use parameter sequence instead of
named parameters:
(multiple-value-setq (sc mi hr da mo yr)
(get-decoded-time))
(setq months
'("Jan" "Feb" "Mar" "Apr" "May" "Jun"
"Jul" "Aug" "Sep" "Oct" "Nov" "Dec"))
(setq month (nth (+ -1 mo) months))
(setq dtstr (format nil "~4d.~a.~2,'0s ~2,'0d:~2,'0d:~2,'0d ~
yr month da hr mi sc))
(setq ip (cdr (assoc :REMOTE_ADDR *environment-list*)))
(setq path (cdr (assoc :PATH *environment-list*)))
(format t "Content-type: text/plain~%~%~
The date&time is currently ~A in California.~%~%~
The IP number ~A is where your client/browser is located.~%~%"
The PATH is ~A currently~%(the only environment variable ~
common to both CGI and login).~%"
dtstr ip path)
Hmm, I'll have to write a meta-format macro which can take something
like this, where you declare what sexpr-bracketing characters you want
to use within the format string:
(mformat t "<>"
"Content-type: text/plain~%~%~
The date&time is currently <dtstr> in California.~%~%~
The IP number <ip> is where your client/browser is located.~%~%"
The PATH is <path> currently~%(the only environment variable ~
common to both CGI and login).~%")
and it pulls out each sexpr from the format string replacing it with a
~A reference, putting the original sexpr at the end as a parameter to
format. Let's see, we already have JSP (Java Server Pages), ASP, PHP,
so I guess I'd call this format Lisp Server Pages. :-)
If you want to do a calculation that returns a result, no problem:
"Hello test, start with <(setq x 1)> and keep incrementing it
<(let ((ls (list))) (loop while (< x 10) do (push (incf x) ls)) (reverse ls))>
until it reaches <x>, all done."
For a calculation for side-effect only, no output, do <(progn ... "")>.
Back to your suggested changes to perl script. The other change you
suggested was call to some perl-system variable called localtime, which
doesn't need parens after it like a function, nor dollar sign before it
like a regular variable. I've never seen that before, but indeed it
works here, so I change the pure-Perl version to do that:
http://www.rawbw.com/~rem/cgi-bin/h1q-perl.cgi
I haven't decided whether to completely replace the pure-Perl with
that, or explicitly give you credit by showing my naive version
followed by your better version.
As for the labeled-multiline-string trick. I am probably going to set
that up as an alternate version for sure. But it's past my bedtime so
not tonight, maybe tomorrow. Thanks for your two ideas. I put a
temporary reminder with your name in there just now.
.
- References:
- Is anybody's favorite computer programming language not included here?
- From: Robert Maas, see http://tinyurl.com/uh3t
- Re: Is anybody's favorite computer programming language not included here?
- From: John W. Krahn
- Is anybody's favorite computer programming language not included here?
- Prev by Date: Re: Is anybody's favorite computer programming language not included here?
- Next by Date: Re: multiple tasks windows
- Previous by thread: Re: Is anybody's favorite computer programming language not included here?
- Next by thread: Re: Is anybody's favorite computer programming language not included here?
- Index(es):