Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Programing Language: LISP Syntax Problem of Piping Functions
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  20 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Xah Lee  
View profile   Translate to Translated (View Original)
 More options Sep 16 2011, 6:09 pm
Newsgroups: comp.lang.lisp, comp.emacs
From: Xah Lee <xah...@gmail.com>
Date: Fri, 16 Sep 2011 15:09:19 -0700 (PDT)
Local: Fri, Sep 16 2011 6:09 pm
Subject: Programing Language: LISP Syntax Problem of Piping Functions
〈Programing Language: LISP Syntax Problem of Piping Functions〉
http://xahlee.org/comp/lisp_syntax_function_pipe.html

plain text version follows
─────────────────────────────────────────

Programing Language: LISP Syntax Problem of Piping Functions

Xah Lee, 2011-09-16

One of the annoying problem of the lisp nested syntax is the problem
of sequencing functions.

Here's a example i frequently encounter in emacs lisp. I like to
change a string in several ways. Example:

(setq fname (file-name-sans-extension (file-name-nondirectory fname)))
(setq fname (replace-regexp-in-string "-" " " fname))
(setq fname (replace-regexp-in-string "_002d" "-" fname))
fname

Note the repeated reset of a variable. I don't want that. I want to
avoid mutable variables; it's bad in functional programing. So, one
should do like this:

(replace-regexp-in-string "_002d" "-"
 (replace-regexp-in-string "-" " "
  (file-name-sans-extension
   (file-name-nondirectory fname))))

But that has several problems. It's hard to debug. Also, in
conventional lisp code formatting, “emacs-lisp-mode” would format it
like this (expand your window width to prevent line wrapping):

(replace-regexp-in-string "_002d" "-"
                          (replace-regexp-in-string "-" " "
                                                    (file-name-sans-
extension
                                                     (file-name-
nondirectory fname))))

Alternative is a one-liner formatting, but it's hard to read and edit:

(replace-regexp-in-string "_002d" "-" (replace-regexp-in-string "-" "
" (file-name-sans-extension (file-name-nondirectory fname))))

If lisp has adopted its early concept of M-expression as syntax
wrapper, then it could be written like this using a postfix syntax
like unix's pipe |. Here, i show it using Mathematica syntax:

file-name-nondirectory[fname] //
file-name-sans-extension //
Function[replace-regexp-in-string["-", " ", #]] //
Function[replace-regexp-in-string["_002d", "-", #]]

The // is similiar to unix's pipe | operator.

or in Mathematica's prefix notation, with @ as the prefix operator:

Function[replace-regexp-in-string["_002d", "-", #]] @
Function[replace-regexp-in-string["-", " ", #]] @
file-name-sans-extension @
file-name-nondirectory[fname]

Note that in functional languages (e.g. Haskell, OCaml), they have
both prefix and postfix operators. Usually the space character is used
as context-sensitive implicit prefix operator. e.g. f x means “f”
applied to “x”, and f a b c means (((f a) b) c). In Ruby, Perl,
usually they have postfix operator desguised as calling object's
methods. In perl, it's ->, in Ruby, it's just a dot ..

For detail, see:

    The Concepts and Confusions of Prefix, Infix, Postfix and Fully
Nested Notations
    Unix Pipe As Functional Language
    Programing Language: A Ruby Illustration of Lisp Problems

Also note, that even Haskell and OCaml support postfix and prefix
syntax, but their syntax is a syntax soup. That is, it's one bunch of
ad hoc designs with no consistancy, systematic grammar, or
mathematical foundation. They are not much better than the syntax soup
of C-like langs. The symbols are used promiscuously (see: Problems of
Symbol Congestion in Computer Languages (ASCII Jam; Unicode;
Fortress)) and the forms are idiosyncratic, e.g. i++, ++i, for(;;){},
while(){}, 0x123, expr1 ? expr2 : expr3, sprint(…%s…,…), …. The only
language i know whose syntax approaches a systematic grammar is
Mathematica. See: The Concepts and Confusions of Prefix, Infix,
Postfix and Fully Nested Notations and Math Notations, Computer
Languages, and the “Form” in Formalism.

 Xah


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Piotr Chamera  
View profile  
 More options Sep 17 2011, 5:39 am
Newsgroups: comp.lang.lisp, comp.emacs
From: Piotr Chamera <piotr_cham...@poczta.onet.pl>
Date: Sat, 17 Sep 2011 11:39:28 +0200
Local: Sat, Sep 17 2011 5:39 am
Subject: Re: Programing Language: LISP Syntax Problem of Piping Functions
W dniu 2011-09-17 00:09, Xah Lee pisze:
> Programing Language: LISP Syntax Problem of Piping Functions

> Xah Lee, 2011-09-16

> One of the annoying problem of the lisp nested syntax is the problem
> of sequencing functions.

> Here's a example i frequently encounter in emacs lisp. I like to
> change a string in several ways. Example:

> (setq fname (file-name-sans-extension (file-name-nondirectory fname)))
> (setq fname (replace-regexp-in-string "-" " " fname))
> (setq fname (replace-regexp-in-string "_002d" "-" fname))
> fname

 > (...)

You can always cook a macro to simplify this.

For example (in Common Lisp):

(defmacro sequential (marker &rest operations)
   (labels ((make-step (ops)
             (if (null (cdr ops))
                 (car ops)
                 (substitute-if
                  (make-step (cdr ops))
                  (lambda (x) (eq x marker))
                  (car ops)))))
     (make-step (reverse operations))))

; usage
(sequential :x
            (+ 1 2)
            (* :x 5)
            (/ 23 :x))

(macroexpand-1
'(sequential :x
   (file-name-sans-extension (file-name-nondirectory fname))
   (replace-regexp-in-string "-" " " :x)
   (replace-regexp-in-string "_002d" "-" :x))
)

 > (REPLACE-REGEXP-IN-STRING "_002d" "-"
    (REPLACE-REGEXP-IN-STRING "-" " "
     (FILE-NAME-SANS-EXTENSION (FILE-NAME-NONDIRECTORY FNAME))))

Probably this has many traps I am not aware of,
but seems to work in simple cases.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pascal J. Bourguignon  
View profile  
 More options Sep 17 2011, 11:45 am
Newsgroups: comp.lang.lisp, comp.emacs
From: "Pascal J. Bourguignon" <p...@informatimago.com>
Date: Sat, 17 Sep 2011 17:45:08 +0200
Local: Sat, Sep 17 2011 11:45 am
Subject: Re: Programing Language: LISP Syntax Problem of Piping Functions

Piotr Chamera <piotr_cham...@poczta.onet.pl> writes:
> W dniu 2011-09-17 00:09, Xah Lee pisze:
>> Programing Language: LISP Syntax Problem of Piping Functions
> You can always cook a macro to simplify this.
> ; usage
> (sequential :x
>        (+ 1 2)
>        (* :x 5)
>        (/ 23 :x))

If the OP ever gave more attention to what was written in cll than to
his own navel, he would have long know about such macros.

For example,
http://groups.google.com/group/comp.lang.lisp/msg/456d141214e1f575?hl=en
but there are much older posts on the same subject.

--
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marco Antoniotti  
View profile  
 More options Sep 17 2011, 2:10 pm
Newsgroups: comp.lang.lisp
From: Marco Antoniotti <marc...@gmail.com>
Date: Sat, 17 Sep 2011 11:10:57 -0700 (PDT)
Local: Sat, Sep 17 2011 2:10 pm
Subject: Re: Programing Language: LISP Syntax Problem of Piping Functions

The main problem with your post is that Xah does not like Common Lisp.

Cheers
--
MA


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Xah Lee  
View profile  
 More options Sep 18 2011, 2:14 am
Newsgroups: comp.lang.lisp, comp.emacs
From: Xah Lee <xah...@gmail.com>
Date: Sat, 17 Sep 2011 23:14:29 -0700 (PDT)
Local: Sun, Sep 18 2011 2:14 am
Subject: Re: Programing Language: LISP Syntax Problem of Piping Functions

a decade ago, i didn't know lisp macro, but due to my admiration of
its Mathematica kinship and the grand-daddy of AI, i thought lisp
macros is a wonderful thing, powerful thing, a thing that allows one
to make arbitrary changes to the language's syntax on the fly.

today, i know, that lisp macros is the most motherfucking fuck in the
whole world of science in computer language.

which fuckhead invented lisp macros hack? I don't presume it's the
same guy who invented lisp. Anyone care to recite the history of lisp
macro?

without being knowledgeable of lisp macro history, my educated guess
is that its the forerunner that evolved into pattern matching proper a
la Mathematica.

 Xah ∑ http://xahlee.org/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Kastrup  
View profile  
 More options Sep 18 2011, 4:16 am
Newsgroups: comp.lang.lisp, comp.emacs
From: David Kastrup <d...@gnu.org>
Date: Sun, 18 Sep 2011 10:16:52 +0200
Local: Sun, Sep 18 2011 4:16 am
Subject: Re: Programing Language: LISP Syntax Problem of Piping Functions

Xah Lee <xah...@gmail.com> writes:
> a decade ago, i didn't know lisp macro, but due to my admiration of
> its Mathematica kinship and the grand-daddy of AI, i thought lisp
> macros is a wonderful thing, powerful thing, a thing that allows one
> to make arbitrary changes to the language's syntax on the fly.

Nonsense.  You can't change the reader syntax.  Whether or not you are
using macros, the expressions you evaluate are read in completely
first.  Macros don't change the syntax but rather the evaluation order.

> today, i know, that lisp macros is the most motherfucking fuck in the
> whole world of science in computer language.

> which fuckhead invented lisp macros hack? I don't presume it's the
> same guy who invented lisp. Anyone care to recite the history of lisp
> macro?

What problem do you have?  It is a rather basic concept easily
implemented.  The typical evaluator can be written (omitting the error
cases) as

(defun eval-list (list)
  (if (atom list) list
      (cons (eval (car list)) (eval-list (cdr list)))))

(defun eval (elem)
  (if (atom elem) elem
    (let ((head (eval (car elem))))
         (if (macrop head) (eval (apply head (cdr elem)))
                           (apply head (eval-list (cdr elem)))))))

The last two lines are all that it takes to implement macros vs
functions.

That's much more straightforward than backquotes which are often
convenient (but not required) in connection with macros.

> without being knowledgeable of lisp macro history, my educated guess
> is that its the forerunner that evolved into pattern matching proper a
> la Mathematica.

What would make this an "educated guess"?  I can see no connection with
pattern matching whatsoever.

--
David Kastrup


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pascal J. Bourguignon  
View profile  
 More options Sep 18 2011, 4:19 am
Newsgroups: comp.lang.lisp, comp.emacs
From: "Pascal J. Bourguignon" <p...@informatimago.com>
Date: Sun, 18 Sep 2011 10:19:17 +0200
Local: Sun, Sep 18 2011 4:19 am
Subject: Re: Programing Language: LISP Syntax Problem of Piping Functions

David Kastrup <d...@gnu.org> writes:
> Xah Lee <xah...@gmail.com> writes:
>> without being knowledgeable of lisp macro history, my educated guess
>> is that its the forerunner that evolved into pattern matching proper a
>> la Mathematica.

> What would make this an "educated guess"?  I can see no connection with
> pattern matching whatsoever.

A better question would be "What education?"  
Specifically, "What education Xah Lee ever received?"

--
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tim Bradshaw  
View profile  
 More options Sep 18 2011, 7:48 am
Newsgroups: comp.lang.lisp
From: Tim Bradshaw <t...@tfeb.org>
Date: Sun, 18 Sep 2011 12:48:50 +0100
Local: Sun, Sep 18 2011 7:48 am
Subject: Re: Programing Language: LISP Syntax Problem of Piping Functions
On 2011-09-18 07:14:29 +0100, Xah Lee said:

> without being knowledgeable of lisp macro history, my educated guess
> is that its the forerunner that evolved into pattern matching proper a
> la Mathematica.

No: macros have nothing to do with pattern matching.  Obviously you
don't understand them at all.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jvt  
View profile  
 More options Sep 18 2011, 9:24 am
Newsgroups: comp.lang.lisp
From: jvt <vincent.to...@gmail.com>
Date: Sun, 18 Sep 2011 06:24:32 -0700 (PDT)
Local: Sun, Sep 18 2011 9:24 am
Subject: Re: Programing Language: LISP Syntax Problem of Piping Functions
You don't even need to bring macros into this.  You need several
functions which are short enough to
define here:

(define (comp2 f1 f2)
 (lambda (&rest args)
   (funcall f1 (apply f2 args)))

(define (compose &rest fs)
  (reduce comp2 (reverse fs)))

(define (>partial f1 &rest args)
  (lambda (&rest unapplied-args)
     (apply f1 (append args unapplied-args))))

(define (partial< f1 &rest args)
  (lambda (&rest unapplied-args)
     (apply f1 (append unapplied-args args)

(funcall (compose (>partial #+ 2) (>partial #'* 3) (partial< #'/ 10))
         10)

I'd argue, despite all this, that if you want to do this kind of point
free, pipe ish programming,
you should just refactor your code, because your packing too much
information into
too much space, and, just like pipe-heavy bash scripts, no one is
going to want to read
them later.

Or program in Factor.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marco Antoniotti  
View profile  
 More options Sep 18 2011, 4:03 pm
Newsgroups: comp.lang.lisp
From: Marco Antoniotti <marc...@gmail.com>
Date: Sun, 18 Sep 2011 13:03:02 -0700 (PDT)
Local: Sun, Sep 18 2011 4:03 pm
Subject: Re: Programing Language: LISP Syntax Problem of Piping Functions

On Sunday, September 18, 2011 1:48:50 PM UTC+2, Tim Bradshaw wrote:
> On 2011-09-18 07:14:29 +0100, Xah Lee said:

> > without being knowledgeable of lisp macro history, my educated guess
> > is that its the forerunner that evolved into pattern matching proper a
> > la Mathematica.

> No: macros have nothing to do with pattern matching.  Obviously you
> don't understand them at all.

But macros are very useful if you want to build pattern matching.  Another thing that was not understood. :)

Cheers
--
MA


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Xah Lee  
View profile  
 More options Sep 18 2011, 6:19 pm
Newsgroups: comp.lang.lisp, comp.emacs
From: Xah Lee <xah...@gmail.com>
Date: Sun, 18 Sep 2011 15:19:41 -0700 (PDT)
Local: Sun, Sep 18 2011 6:19 pm
Subject: Re: Programing Language: LISP Syntax Problem of Piping Functions
On Sep 17, 11:14 pm, Xah Lee <xah...@gmail.com> wrote:

> which fuckhead invented lisp macros hack? I don't presume it's the
> same guy who invented lisp. Anyone care to recite the history of lisp
> macro?

answer:
https://plus.google.com/u/0/112757647855302148298/posts/ZAE5mMdvxc4

 Xah


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Xah Lee  
View profile  
 More options Sep 18 2011, 6:26 pm
Newsgroups: comp.lang.lisp, comp.emacs
From: Xah Lee <xah...@gmail.com>
Date: Sun, 18 Sep 2011 15:26:23 -0700 (PDT)
Local: Sun, Sep 18 2011 6:26 pm
Subject: Re: Programing Language: LISP Syntax Problem of Piping Functions
On Sep 18, 3:19 pm, Xah Lee <xah...@gmail.com> wrote:

> On Sep 17, 11:14 pm, Xah Lee <xah...@gmail.com> wrote:

> > which fuckhead invented lisp macros hack? I don't presume it's the
> > same guy who invented lisp. Anyone care to recite the history of lisp
> > macro?

> answer: https://plus.google.com/u/0/112757647855302148298/posts/ZAE5mMdvxc4

>  Xah

also of interest, if you want to know what i think of the various lang
creators.

https://plus.google.com/u/0/112757647855302148298/posts/dYs3vKyQwti

if you need a g+ invite, click on the link at bottom of:
http://xahlee.org/funny/whats_is_googleplus.html

i have 144 invite left.

 Xah


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Kastrup  
View profile  
 More options Sep 19 2011, 3:50 am
Newsgroups: comp.lang.lisp, comp.emacs
From: David Kastrup <d...@gnu.org>
Date: Mon, 19 Sep 2011 09:50:06 +0200
Local: Mon, Sep 19 2011 3:50 am
Subject: Re: Programing Language: LISP Syntax Problem of Piping Functions

Xah Lee <xah...@gmail.com> writes:
> On Sep 18, 3:19 pm, Xah Lee <xah...@gmail.com> wrote:
>> On Sep 17, 11:14 pm, Xah Lee <xah...@gmail.com> wrote:

>> > which fuckhead invented lisp macros hack? I don't presume it's the
>> > same guy who invented lisp. Anyone care to recite the history of lisp
>> > macro?

>> answer: https://plus.google.com/u/0/112757647855302148298/posts/ZAE5mMdvxc4

>> Xah

> also of interest, if you want to know what i think of the various lang
> creators.

I'd rather read Bukowski in the original.

--
David Kastrup


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tim Bradshaw  
View profile  
 More options Sep 19 2011, 5:52 am
Newsgroups: comp.lang.lisp
From: Tim Bradshaw <t...@tfeb.org>
Date: Mon, 19 Sep 2011 10:52:58 +0100
Local: Mon, Sep 19 2011 5:52 am
Subject: Re: Programing Language: LISP Syntax Problem of Piping Functions
On 2011-09-18 21:03:02 +0100, Marco Antoniotti said:

> But macros are very useful if you want to build pattern matching.  
> Another thing that was not understood. :)

Yes, and you can also a macro system which uses pattern matching (I
don't really understand Scheme's macro system, but they seem to be at
least partly pattern-based).  But the two concepts are orthoganal.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tim Bradshaw  
View profile  
 More options Sep 19 2011, 5:56 am
Newsgroups: comp.lang.lisp
From: Tim Bradshaw <t...@tfeb.org>
Date: Mon, 19 Sep 2011 10:56:24 +0100
Local: Mon, Sep 19 2011 5:56 am
Subject: Re: Programing Language: LISP Syntax Problem of Piping Functions
On 2011-09-19 10:52:58 +0100, Tim Bradshaw said:

> Yes, and you can also a macro system which uses pattern matching (I
> don't really understand Scheme's macro system, but they seem to be at
> least partly pattern-based).  But the two concepts are orthoganal.

PS I'm not disagreeing with the article I'm responding to, it just
looks that way!

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marco Antoniotti  
View profile  
 More options Sep 19 2011, 6:15 am
Newsgroups: comp.lang.lisp
From: Marco Antoniotti <marc...@gmail.com>
Date: Mon, 19 Sep 2011 03:15:05 -0700 (PDT)
Local: Mon, Sep 19 2011 6:15 am
Subject: Re: Programing Language: LISP Syntax Problem of Piping Functions

On Monday, September 19, 2011 11:56:24 AM UTC+2, Tim Bradshaw wrote:
> On 2011-09-19 10:52:58 +0100, Tim Bradshaw said:

> > Yes, and you can also a macro system which uses pattern matching (I
> > don't really understand Scheme's macro system, but they seem to be at
> > least partly pattern-based).  But the two concepts are orthoganal.

> PS I'm not disagreeing with the article I'm responding to, it just
> looks that way!

The way it looks, Bradshaw, is that it's a chicken-n-egg thingy that the some people don't get :) :)

Cheers
--
MA


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Antti J Ylikoski  
View profile  
 More options Sep 19 2011, 11:33 am
Newsgroups: comp.lang.lisp, comp.emacs
From: Antti J Ylikoski <antti.yliko...@aalto.fi>
Date: Mon, 19 Sep 2011 18:33:33 +0300
Local: Mon, Sep 19 2011 11:33 am
Subject: Re: Programing Language: LISP Syntax Problem of Piping Functions
18.9.2011 11:19, Pascal J. Bourguignon kirjoitti:

> David Kastrup<d...@gnu.org>  writes:

>> Xah Lee<xah...@gmail.com>  writes:
>>> without being knowledgeable of lisp macro history, my educated guess
>>> is that its the forerunner that evolved into pattern matching proper a
>>> la Mathematica.

>> What would make this an "educated guess"?  I can see no connection with
>> pattern matching whatsoever.

> A better question would be "What education?"
> Specifically, "What education Xah Lee ever received?"

Well -- perhaps the poster is referring to the fact that the parameter
list of a macro is sort of pattern matched with the actual argument
SEXP, which behaviour has been duplicated for the programmer in the
DESTRUCTURING-BIND.

Cheers, andy


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
WJ  
View profile   Translate to Translated (View Original)
 More options Mar 24 2012, 8:23 pm
Newsgroups: comp.lang.lisp, comp.emacs
From: "WJ" <w_a_x_...@yahoo.com>
Date: 25 Mar 2012 00:23:16 GMT
Local: Sat, Mar 24 2012 8:23 pm
Subject: Re: Programing Language: LISP Syntax Problem of Piping Functions

Clojure has the "threading" macros -> and ->>.

user=> (-> -3 (Math/abs) (Math/sqrt) (Math/exp))
5.6522336740340915


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
namekuseijin  
View profile   Translate to Translated (View Original)
 More options Mar 25 2012, 3:04 pm
Newsgroups: comp.lang.lisp
From: namekuseijin <namekusei...@gmail.com>
Date: Sun, 25 Mar 2012 12:04:12 -0700 (PDT)
Local: Sun, Mar 25 2012 3:04 pm
Subject: Re: Programing Language: LISP Syntax Problem of Piping Functions
Em sexta-feira, 16 de setembro de 2011 19h09min19s UTC-3, Xah Lee  escreveu:

I've got math function composition (o f g etc) and argument lifting (^ + 1) in my personal Scheme lib.  With them, instead of writing, say:

(string-prepend "  Call me no more!!!"
    (replace "this" "that"
             (replace "You" "I do"
                      (replace "?" ", I do"
                               "this is right?!  You think so?!"))))

I write

((o (^ string-prepend "  Call me no more!!!")
    (^ replace "this" "that")
    (^ replace "You" "I do")
    (^ replace "?" ", You"))
 "this is right?!  You think so?!")

or

(define replaces
  (o (^ string-prepend "  Call me no more!!!")
     (^ replace "this" "that")
     (^ replace "You" "I do")
     (^ replace "?" ", You")))

(replaces phrase)

all evaluating to: "that is right, I do!  I do think so, I do!  Call me no more!!!"

Notice the chain of functions are put in the very same order they are normally called.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
WJ  
View profile  
 More options Dec 16 2012, 5:52 pm
Newsgroups: comp.lang.lisp, comp.emacs
From: "WJ" <w_a_x_...@yahoo.com>
Date: 16 Dec 2012 22:52:18 GMT
Local: Sun, Dec 16 2012 5:52 pm
Subject: Re: Programing Language: LISP Syntax Problem of Piping Functions

WJ wrote:

> Clojure has the "threading" macros -> and ->>.

> user=> (-> -3 (Math/abs) (Math/sqrt) (Math/exp))
> 5.6522336740340915

user=> (-> -3 Math/abs Math/sqrt Math/exp)
5.6522336740340915

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »