txr-users
[Top][All Lists]
Advanced

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

[Txr-users] 55 is out


From: Kaz Kylheku
Subject: [Txr-users] 55 is out
Date: Fri, 27 Jan 2012 15:26:47 -0800
User-agent: Roundcube Webmail/0.4


Hi all,

Obligatory release notes: http://www.kylheku.com/cgit/txr/tree/RELNOTES

I added a few syntactic sugars and some useful semantics also.

In @(output) blocks, you can do indexing and slicing
on lists. This is convenient for things like handling
formats with many columns and such, where you might be
tempted to grope for awk or perl.

The slicing syntax can replace many trivial uses of
@(rep) or @(repeat) where you just want the semantics
of a simple join with a separator string.

Example:

@(bind a ("a" "list" "of" "five" "strings"))
@(output)
@{a[1..4] "-:-"}
@{a[0]} @{a[2]} @{a[4]}
@(end)

The result will be:

list-:-of-:-five
a of strings

In TXR Lisp, the [...] notation is a syntactic sugar for
the dwim operator (dwim ...).   The  A..B notation is
a syntactic sugar for (cons A B).  Thus:

 [foo 1..2 3]

really means

 (dwim foo (cons 1 2) 3)

Examples:

 ;; if func evaluates to a function,
 ;; dwim performs a function call
 [func arg1 arg2]

 ;; vector/list/string slice
 (vec 0..3)

 ;; store in hash table
 (set [myhash "x" nil] "y")

 ;; slice assignment
 ;; replace first and second elements with (1 2 3)
 (set [mylist 0..1] '(1 2 3))

 (let ((s "abc"))
   (inc [s 0])
   s) ;; s is now "bbc"


That's the gist of it.

Cheers ...




reply via email to

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