Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Lisp Data Structure: Looking for an alternative

108 views
Skip to first unread message

WJ

unread,
Nov 16, 2012, 7:17:12 AM11/16/12
to
Kaz Kylheku wrote:

> How would we write this language feature?
>
> (defmacro dolist-destructured ((destructuring-lambda-list
> list &optional result-form)
> &rest body)
> (let ((list-item-sym (gensym "LIST-ITEM-")))
> `(dolist (,list-item-sym ,list ,result-form)
> (destructuring-bind ,destructuring-lambda-list ,list-item-sym
> ,@body))))
>
> (defvar *list* '((1 2) (3 4))
>
> (dolist-destructured ((i j) *list*)
> (format t "~a - ~a~%" i j))
>
> Output:
> 1 - 2
> 3 - 4


Clojure:

user=> (doseq [[i j] '((1 2) (3 4))] (printf "%d -- %d\n" i j))
1 -- 2
3 -- 4

Daniel Rupis

unread,
Nov 16, 2012, 8:48:16 AM11/16/12
to
El viernes, 16 de noviembre de 2012 13:18:17 UTC+1,
WJ said:

Clojure:

> user=> (doseq [[i j] '((1 2) (3 4))] (printf "%d -- %d\n" i j))

Common Lisp

(loop for (i j) in '((1 2) (3 4)) do (format t "~d -- ~d~%" i j))

WJ

unread,
Dec 5, 2012, 9:00:50 PM12/5/12
to
WJ wrote:

> Kaz Kylheku wrote:
>
> > How would we write this language feature?
> >
> > (defmacro dolist-destructured ((destructuring-lambda-list
> > list &optional result-form)
> > &rest body)
> > (let ((list-item-sym (gensym "LIST-ITEM-")))
> > `(dolist (,list-item-sym ,list ,result-form)
> > (destructuring-bind ,destructuring-lambda-list ,list-item-sym
> > ,@body))))
> >
> > (defvar list '((1 2) (3 4))
> >
> > (dolist-destructured ((i j) list)
> > (format t "~a - ~a~%" i j))
> >
> > Output:
> > 1 - 2
> > 3 - 4
>
>
> Clojure:
>
> user=> (doseq [[i j] '((1 2) (3 4))] (printf "%d -- %d\n" i j))
> 1 -- 2
> 3 -- 4


EMACS Lisp:

(require 'cl)
(defmacro $ (&rest exprs) `(function* (lambda ,@exprs)))
(mapc ($ ((i j)) (princ (format "%d - %d\n" i j))) '((1 2) (3 4)))

WJ

unread,
Jan 1, 2015, 4:54:04 AM1/1/15
to
WJ wrote:

> Kaz Kylheku wrote:
>
> > How would we write this language feature?
> >
> > (defmacro dolist-destructured ((destructuring-lambda-list
> > list &optional result-form)
> > &rest body)
> > (let ((list-item-sym (gensym "LIST-ITEM-")))
> > `(dolist (,list-item-sym ,list ,result-form)
> > (destructuring-bind ,destructuring-lambda-list ,list-item-sym
> > ,@body))))
> >
> > (defvar list '((1 2) (3 4))
> >
> > (dolist-destructured ((i j) list)
> > (format t "~a - ~a~%" i j))
> >
> > Output:
> > 1 - 2
> > 3 - 4


Gauche Scheme:

(use util.match)
(define-syntax match-dolist
(syntax-rules ()
[(_ (pattern the-list) body ...)
(dolist (x the-list)
(match-let1 pattern x
body ...))]))

(define stuff '((1 2) (3 4)))
(match-dolist ((i j) stuff)
(format #t "~a - ~a~%" i j))

===>

WJ

unread,
Jul 13, 2016, 10:33:50 PM7/13/16
to
Why this is marked as abuse? It has been marked as abuse.
Report not abuse
OCaml:

open Printf;;

List.iter
(fun [i;j] -> printf "%d - %d\n" i j)
[[1;2]; [3;4]] ;;

===>
1 - 2
3 - 4

--
When I was a Revolutionary Marxist, we were all in favour of as much
immigration as possible. It wasn't because we liked immigrants, but because we
didn't like Britain.
dailymail.co.uk/news/article-2301743/How-invasion-immigrants-corner-England-mockery-PMs-promise-close-door.html
0 new messages