txr-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Txr-users] Version 044 is out.


From: Kaz Kylheku
Subject: [Txr-users] Version 044 is out.
Date: Fri, 02 Dec 2011 10:04:28 -0800
User-agent: Roundcube Webmail/0.4


Hi Everyone,

Recently, TXR has sprouted an evaluator for Lisp forms,
thereby exposing the internal data structures.

This area of the language is not well documented yet.

In any place where TXR accepts an expression,
you can use the syntax @compound-form, where compound-form
is a Lisp compound form (list with an operator or function
in the first position).

For instance

 @(bind a @(mapcar (lambda (a) (+ a 1)) '(1 2 3)))


In addition, there is a @(do form1 form2 ...) directive
now for imperatively evaluating some Lisp forms for their
side effects, discarding the return value.

For instance, here is a program which tabulates the frequency
of occurrence of the 26 letters A-Z in the input:

@(do (defvar h (make-hash nil nil t)))
@(collect :vars ())
@(coll :vars ())@\
@{letter /[A-Za-z]/}@(filter :upcase letter)@\
@(do (inc (gethash h letter 0)))@\
@(end)
@(end)
@(do (dohash (key value h)
     (format t "~a: ~a\n" key value)))

This just uses the imperative do to set up and manage
a hash table. Note how the captured variable "letter" is
used as a hash key.

The function call (gethash h letter 0)
means look up letter in the hash table h,
supplying the value 0 if it is not found.

This form can be used as a place which you can
assign, increment, etc.

Thus (inc (gethash h letter 0)) will increment
the number stored in the hash under letter.
Or if the entry does not exist, it will
increment from the default value 0 and create
the entry with the value 1.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]