From: Alan Manuel K. Gloria
Subject: infix notation macro
Date: 
Message-ID: <1142728176.987417.304570@i40g2000cwc.googlegroups.com>
Hello all, I've built an infix notation macro, of the form:
(nfx <expr>)
#n(<expr>)
<expr>::=
(constant | symbol), or
list, or
<expr> <oper> <expr>
<oper>::=
one of a bunch of infix operators, which can be user-defined.

The file I've put them in is rather large (from comments).  I'm
wondering where I could have it posted or something.

The nfx macro, btw, supports prefix notation within its demesne:
#n(x = (cons nil nil))
    => (nil)
#n( (car x) = 42)
    => 42
x
    => (42)
#n( (apply #'max (1 + 42) x) )
    => 43

...so, where can I put this?  I don't have a web page of my own (too
lazy, lol), would anyone like to host this?  The one who wants to host
this gets to have first look at the code!

Alternatively, is there some public library for Lisp I can post this
to?
(come to think of it, is there already a macro for this?)

From: Eric Lavigne
Subject: Re: infix notation macro
Date: 
Message-ID: <1142728888.537286.27620@v46g2000cwv.googlegroups.com>
> Hello all, I've built an infix notation macro
> ...
> (come to think of it, is there already a macro for this?)

There is already an infix library.
http://www.cliki.net/infix

I haven't used it, though, so can't say how similar it is.

Also, the webpage above indicates that the license includes a
non-commercial clause, so there could be a niche for a less restrictive
library.
From: Alan Manuel K. Gloria
Subject: Re: infix notation macro
Date: 
Message-ID: <1142730948.979597.282390@u72g2000cwu.googlegroups.com>
I'd be happy just to find anyone using it ;)

There are some major differences:
f(x) - theirs :: (f x) - mine
a[x,y] - theirs :: a @ x @ y - mine

Also, I just use the Lisp reader plain - I'm reading a list of tokens.
Their syntax, though, allows you to type without spaces between tokens,
whereas my syntax requires spaces between tokens (because the Lisp
reader reads it that way).

They have support for a prefix notation - My logic is, since prefix is
already the default, I let Lisp handle prefix notations and just handle
probably infix notations.  Basically, the difference between (+ 2 3 4)
and (2 + 3 + 4) to me is that the + is in the cadr for infix and car
for the prefix.  A notation like their #i(x*-(y+1)) is #n(x * (- (y +
1))) to me.

Adding new infix operators to their infix notation requires editing the
file (to get at the precedence list), while my precedence is expressed
as a number (the lower the number, the greater the precedence):
#|theirs|#
(defparameter *operator-ordering*
    '(( \[ \( \! ) ......))
.
.
.
(define-token-operator and ...)
#|mine|#
(definfix +
    :precedence 40
    :associativity :left ;default, actually
    :function-name + ;default to same symbol
    :fungible t) ;defaults to t,too

...and my file is just 10k and doesn't have a restrictive license. ;)
Anyone interested?

In all, though, their infix library seems pretty good (better than
mine), but I think my target is more for those who would like a dash of
infix notation while mostly keeping function calls the same (f x y).
From: Eric Lavigne
Subject: Re: infix notation macro
Date: 
Message-ID: <1142733557.827427.54430@j33g2000cwa.googlegroups.com>
> There are some major differences:
> f(x) - theirs :: (f x) - mine
> a[x,y] - theirs :: a @ x @ y - mine

That is a really ugly array access notation. Hopefully this is
optional.

>
> Also, I just use the Lisp reader plain - I'm reading a list of tokens.
> Their syntax, though, allows you to type without spaces between tokens,
> whereas my syntax requires spaces between tokens (because the Lisp
> reader reads it that way).

That doesn't sound like a big loss. Also, it means we can still use
lispy names like this-is-a-name-that-is-way-too-long__:-)

> (define-token-operator and ...)
> #|mine|#
> (definfix +
>     :precedence 40
>     :associativity :left ;default, actually
>     :function-name + ;default to same symbol
>     :fungible t) ;defaults to t,too

This looks nice.

>
> ...and my file is just 10k and doesn't have a restrictive license. ;)
> Anyone interested?

I don't need an infix library right now, but I'd be happy to host a 10k
file if you don't want the trouble of setting up an account at
common-lisp.net or sourceforge.

Email to ············@gmail.com
and it will go on my webpage at plaza.ufl.edu/lavigne/

> In all, though, their infix library seems pretty good (better than
> mine), but I think my target is more for those who would like a dash of
> infix notation while mostly keeping function calls the same (f x y).

In other words, folks that like programming in Lisp, but don't want
their equations to look like a mess :-p

I actually have that issue, but my code has so few of those long messy
equations that it's not worth learning a new library.
From: Alan Manuel K. Gloria
Subject: Re: infix notation macro
Date: 
Message-ID: <1142735139.112210.61790@p10g2000cwp.googlegroups.com>
> That is a really ugly array access notation. Hopefully this is
> optional.
Since you can embed prefix syntax within a (nfx ...) form, it is
effectively optional:
#n( x = (make-array '(3 2)) )
   => #2A((nil nil) (nil nil) (nil nil))
#n( (aref x 0 1) = 2)
   => 2
#n( (aref x 0 1))
   => 2
#n( x @ 0 @ 1)
   => 2
x
   => #2A((nil 2) (nil nil) (nil nil))

> In other words, folks that like programming in Lisp, but don't want
> their equations to look like a mess :-p
Exactly!  Gosh, why wasn't I that specific?  Must be the lack of sleep
lol.

> I actually have that issue, but my code has so few of those long messy
> equations that it's not worth learning a new library.
It's not that hard ;).  You just type more spaces.  Here are a few more
samples:
#n(a = 4) ;dang I added #n on a whim, now I'm more used to it than (nfx
...)
  => 4
#n(b = c = 2)
  => 0
#n( ((- b) + (sqrt (b ** 2 - 4 * a * c))) / (2 * a) )
  => #C(-0.24999999999999997 0.66143782776614757)
From: Eric Lavigne
Subject: Re: infix notation macro
Date: 
Message-ID: <1142735828.106716.298580@u72g2000cwu.googlegroups.com>
> Hello all, I've built an infix notation macro, of the form:
> (nfx <expr>)
> #n(<expr>)
> <expr>::=
> (constant | symbol), or
> list, or
> <expr> <oper> <expr>
> <oper>::=
> one of a bunch of infix operators, which can be user-defined.
>
> The file I've put them in is rather large (from comments).  I'm
> wondering where I could have it posted or something.

Alan's infix code, with documentation, is available here:
plaza.ufl.edu/lavigne/

The syntax is extendable, and the license is public domain (with
encouragement to let Alan know if you find the library amusing).
From: Stefan Scholl
Subject: Re: infix notation macro
Date: 
Message-ID: <0T30lsdeIjthNv8%stesch@parsec.no-spoon.de>
Alan Manuel K. Gloria <········@gmail.com> wrote:
> Hello all, I've built an infix notation macro, of the form:

Why?
From: Alan Manuel K. Gloria
Subject: Re: infix notation macro
Date: 
Message-ID: <1142768458.786496.17620@v46g2000cwv.googlegroups.com>
1.)  Mostly so that I can do stuff like this:
#|ebers-moll equation, which is the current going through an npn
transistor given a certain voltage across its input|#
(nfx
    (defun ebersmoll (vbe &key (vt 0.026) (is 30e-6) )
         ( is * ((exp (vbe / vt)) -1)) ))

2.)  I read somewhere on the group (I think it was in the TwinLisp
thread) that someone would like to occassionally have a bit of infix
notation, even if it needed spaces between tokens.  I can't remember
who it is, but whoever it was, this is for you ;)

3.)  Because it lets me practice some Common Lisp coding (the Lisp we
use in the office was an offshoot from Franz Lisp from way back, was
originally dynamic binding only, and is now being enhanced to be more
similar to Scheme).

4.)  It is one more proof of Lisp's flexibility ("See! Lisp is so good,
you don't even need to write a separate parser to do infix notation!
Wafuu!").

5.) For my own amusement.  Look ma, I made an infix notation for Lisp!

Anyway I'm thinking of adding single-argument prefix functions such
that they will have implied parentheses:
#n(j = #c(0 1))
#n( foo = cos theta + j * sin theta )

P.S. Thanks Eric!  I owe you one!