[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Re: Python gets macros - now XML does too

William James

8/22/2015 5:10:00 PM

Frank Buss wrote:

> Just a simple example. If I want to create a square, I could write it like
> this:
>
> (iterate 4


CL does not have "iterate".


> (iterate 4 (princ "*"))
> (terpri))
>
> and the output:
>
> ****
> ****
> ****
> ****
>
> If you want to specify the expression for outputting a character and for
> newline, but you don't want to write every time the nested structure, it
> would be a good idea to implement it as a macro:
>
> (defmacro square (n one-element newline)
> `(iterate ,n
> (iterate ,n ,one-element)
> ,newline))
>
> Then you can use it like this:
>
> CL-USER > (square 3 (princ "x") (format t "~%"))
> xxx
> xxx
> xxx

Gauche Scheme:

(define (square n display-element newline)
(dotimes (n)
(dotimes (n) (display-element))
(newline)))

gosh> (square 4 (cut display #\*) newline)
****
****
****
****

--
This is war, and our greatest enemy is the enemy within: the submissive,
apologetic, guilt-ridden, self-hating drone. The moment we manage to destroy
the enemy within, destroying the rest of our enemies will be a walk in the
park. http://www.kolumbus.fi/aquilon/londonsp...
2 Answers

Kaz Kylheku

8/24/2015 11:49:00 PM

0

On 2015-08-22, WJ <w_a_x_man@yahoo.com> wrote:
> Frank Buss wrote:
>
>> Just a simple example. If I want to create a square, I could write it like
>> this:
>>
>> (iterate 4
>
> CL does not have "iterate".

True, but to an even lesser extent than that "C doesn't have strdup".

William James

10/30/2015 4:06:00 PM

0

WJ wrote:

> Frank Buss wrote:
>
> > Just a simple example. If I want to create a square, I could write it like
> > this:
> >
> > (iterate 4
>
>
> CL does not have "iterate".
>
>
> > (iterate 4 (princ "*"))
> > (terpri))
> >
> > and the output:
> >
> > ****
> > ****
> > ****
> > ****
> >
> > If you want to specify the expression for outputting a character and for
> > newline, but you don't want to write every time the nested structure, it
> > would be a good idea to implement it as a macro:
> >
> > (defmacro square (n one-element newline)
> > `(iterate ,n
> > (iterate ,n ,one-element)
> > ,newline))
> >
> > Then you can use it like this:
> >
> > CL-USER > (square 3 (princ "x") (format t "~%"))
> > xxx
> > xxx
> > xxx
>
> Gauche Scheme:
>
> (define (square n display-element newline)
> (dotimes (n)
> (dotimes (n) (display-element))
> (newline)))
>
> gosh> (square 4 (cut display #\*) newline)
> ****
> ****
> ****
> ****

MatzLisp (Ruby):

def square n, display_element, newline
n.times{ n.times{ display_element.call}; send newline}
end

square 5, proc{print :*}, :puts

*****
*****
*****
*****
*****

--
The struggle of our time is to concentrate, not to dissipate: to renew our
association with traditional wisdom: to re-establish a vital connection between
the individual and the race. It is, in a word, a struggle against Liberalism.
--- T. S. Elliot