Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

You fill a much-needed gap.


comp / comp.lang.lisp / Re: Reasons for preferring Lisp, and for what

SubjectAuthor
o Re: Reasons for preferring Lisp, and for whatB. Pym

1
Subject: Re: Reasons for preferring Lisp, and for what
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Mon, 5 Aug 2024 05:38 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: Reasons for preferring Lisp, and for what
Date: Mon, 5 Aug 2024 05:38:04 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <v8pofo$h4dr$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Mon, 05 Aug 2024 07:38:05 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="7494c0c807b5ee450e56fbedd80570a2";
logging-data="561595"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/8pLi0j6/yOavE9DtAzmZP"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:qbBNeGtCa7aFh61GRuoK5f1IEbU=
View all headers

Joel Ray Holveck wrote:

> As a concrete example, suppose (as I did in a program I recently
> wrote) that you have a string with several arbitrary variable names
> you need to substitute in, and a hash with their values. This can be
> done in one line in Perl:
> # $string holds something like:
> # 'The $dimension of the $obj is $length cm.'
> # %vars holds something like:
> # { $dimension => length, $obj => plank, $length => 105 }
> $string =~ s/\$(\S+)/$vars->{$1}/g;
>
> Now, look at a Lisp parallel. You have a list, and you want to
> substitute keywords with their values from an alist:
> ;; LIST holds something like:
> ;; (the :dimension of the :object is :value cm)
> ;; VARS holds something like:
> ;; ((:dimension . length) (:object . plank) (:value . 105))
> (mapcar #'(lambda (elt)
> (if (keywordp elt)
> (cdr (assoc elt vars))
> elt))
> list)

newLISP

(define str "The $dimension of the $obj is $length cm.")
(define table '((dimension "length") (obj "plank") (length "105")))

(replace "\\$(\\w+)" str (lookup (sym $1) table) 0)

"The length of the plank is 105 cm."

1

rocksolid light 0.9.8
clearnet tor