Re: [racket-users] infix notation embedded in Racket

2015-04-25 Thread Jens Axel Søgaard
> 2015-04-24 14:44 GMT+02:00 Jens Axel Søgaard :
>
>> The arrows disappear when I use the at-exp syntax:  @${b^2-4*a*x}.
>> I am not sure why. Anyone?
>>
>
Thanks to Alexander for submitting a fix.

/Jens Axel

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] infix notation embedded in Racket

2015-04-25 Thread Jens Axel Søgaard
2015-04-24 14:44 GMT+02:00 Jens Axel Søgaard :

> The arrows disappear when I use the at-exp syntax:  @${b^2-4*a*x}.
> I am not sure why. Anyone?
>

I haven't figured it out yet, but it seems to have worked at some point.

I have found this:


(define-syntax ($ stx) (syntax-case stx () [(_ item ...) (let* ([from-at?
(syntax-property stx 'scribble)]) (if from-at? ; reintroduce the original
(discarded) indentation (with-syntax ([(item ...) (let loop ([items
(syntax->list #'(item ...))]) (if (null? items) '() (let* ([fst (car items)]
[prop (syntax-property fst 'scribble)] [rst (loop (cdr items))]) (cond
[(eq? prop 'indentation) rst] [(not (and (pair? prop) (eq? (car prop)
'newline))) (cons fst rst)] [else (cons (datum->syntax fst (cadr prop) fst)
rst)]]) #'($$ item ...)) #'($$ item ...)))]))

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] infix notation embedded in Racket

2015-04-25 Thread Jens Axel Søgaard
2015-04-24 14:44 GMT+02:00 Jens Axel Søgaard :

>
> The planet package took a *very* long time to install, so I intend to
> upload a version to pkg.racket-lang.org.
>

The infix package is now available through pkg.racket-lang.org.

/Jens Axel

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] infix notation embedded in Racket

2015-04-24 Thread Alexander D. Knauth

On Apr 24, 2015, at 8:44 AM, Jens Axel Søgaard  wrote:

> As it turns out, it is at-exp that are at fault.
> 
> The screen shot below show that arrows and renaming works when using the 
> infix packages with the syntax:
>   ($ "b^2-4*a*x")
> 
> Note that it works even for identifiers inside the string.

Oh! Well that’s a pleasant surprise! I didn’t know that check-syntax arrows 
could point to “identifiers” within strings! 

> The arrows disappear when I use the at-exp syntax:  @${b^2-4*a*x}. 
> I am not sure why. Anyone?

I tried this and this worked with at-exp:
#lang at-exp racket
(require (for-syntax syntax/parse))
(define-syntax m
  (syntax-parser
[(m str)
 (datum->syntax #'str (string->symbol (syntax-e #'str)) #'str #'str)]))
(let ([x 5])
  @m{x})

But that made me think of doing this:

In main.ss, line 68, you use datum->syntax with three arguments, but it works 
if you add the fourth argument:
 (datum->syntax 
  #'str
  (apply string-append
 (map syntax->datum 
  (syntax->list #'(str str* ...
  (list (syntax-source #'str)
line col pos
(syntax-span #'str))
   #'str)

> The planet package took a *very* long time to install, so I intend to upload 
> a version to pkg.racket-lang.org.
> 
> /Jens Axel
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] infix notation embedded in Racket

2015-04-24 Thread Jens Axel Søgaard
2015-04-24 0:18 GMT+02:00 Alexander D. Knauth :

>
> What’s wrong with at-exp though?
> I personally don’t like (planet soegaard/infix) as much mostly because the
> other options have the benefit of working with DrRacket features such as
> check-syntax arrows and blue-boxes, but that’s just because DrRacket is
> awesome, not because at-exp is bad.
>

As it turns out, it is at-exp that are at fault.

The screen shot below show that arrows and renaming works when using the
infix packages with the syntax:
  ($ "b^2-4*a*x")

Note that it works even for identifiers inside the string.

The arrows disappear when I use the at-exp syntax:  @${b^2-4*a*x}.
I am not sure why. Anyone?

The planet package took a *very* long time to install, so I intend to
upload a version to pkg.racket-lang.org.

/Jens Axel

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: [racket-users] infix notation embedded in Racket

2015-04-24 Thread Jos Koot
Thanks, I take note of that.
I was mislead by the examples in the infix docs of Jens Axel Søgaard.
These examples start with #lang at-exp scheme.
Sorry, my fault.
Jos

  _  

From: Alexander D. Knauth [mailto:alexan...@knauth.org] 
Sent: viernes, 24 de abril de 2015 12:59
To: Jos Koot
Cc: Jens Axel Søgaard; racket-users@googlegroups.com
Subject: Re: [racket-users] infix notation embedded in Racket



On Apr 24, 2015, at 3:40 AM, Jos Koot  wrote:


With respect to at-exp: I want my infix to be a simple macro that can be
required within any arbitrary #lang racket module and cooperates well with
all binding forms in that module.


Well, since at-exp can be used with not only #lang racket but others as well
(scheme, rackjure, clojure, afl, sweet-exp, basically anything that looks at
the readtable), and doesn’t interfere with or require anything about the
bindings, at-exp and (planet soegaard/infix) can be used with any arbitrary
#lang whatever module as long as #lang whatever looks at the readtable and
supports require.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] infix notation embedded in Racket

2015-04-24 Thread Alexander D. Knauth

On Apr 24, 2015, at 3:40 AM, Jos Koot  wrote:

> With respect to at-exp: I want my infix to be a simple macro that can be 
> required within any arbitrary #lang racket module and cooperates well with 
> all binding forms in that module.

Well, since at-exp can be used with not only #lang racket but others as well 
(scheme, rackjure, clojure, afl, sweet-exp, basically anything that looks at 
the readtable), and doesn’t interfere with or require anything about the 
bindings, at-exp and (planet soegaard/infix) can be used with any arbitrary 
#lang whatever module as long as #lang whatever looks at the readtable and 
supports require.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: [racket-users] infix notation embedded in Racket

2015-04-24 Thread Jos Koot
Hi Alexander,
 
Thanks for your elaborated answer and the many pointers.
I'll need some time to study the material you have pointed me to.
 
My infix is based on precedence.
It does not have tools to add new operators, but this is an interesting
idea.
I don't know yet how to implement that, especially for operators that can be
used both diadic and monadic.
For associative operators I want to simplify the expansion using it, for
example:
(infix 1 + 2 - 3 + 4 - 5) -> (- (+ 1 2 4) 3 5)
(infix 2 * - 3 * 4) -> (- (* 2 3 4)) where the product of the monacic signs
forms one single sign for the whole product.
 
I am planning to evaluate subexpressions consisting of constants only during
expansion, for example:
(infix 1 + 2 - 3 + 4 - 5) -> -1
(infix 2 / - 3) -> -2/3
(infix list('a, 'b, 'c)) -> '(a b c) (I did not yet include list as an
operator, though)
This should not be too difficult. 
 
That my operators can be renamed is simply a consequence of using
free-identifier=? via literal identifiers in syntax-case. It is not a
beforehand intended property by itself.
 
With respect to at-exp: I want my infix to be a simple macro that can be
required within any arbitrary #lang racket module and cooperates well with
all binding forms in that module.
 
I just found out that my infix has a bug. It fails when infix is used within
infix. This may seem unimportant, but may give rise to problems when using a
macro x within infix where x expands to an infix call.
I do require that my infix accepts simple forms of macro calls. Did not yet
find out where the bug is located.
 
I'll study the material and inform you about my findings.
 
Thanks again, Jos Koot

  _  

From: Alexander D. Knauth [mailto:alexan...@knauth.org] 
Sent: viernes, 24 de abril de 2015 0:18
To: Jos Koot
Cc: Jens Axel Søgaard; racket-users@googlegroups.com
Subject: Re: [racket-users] infix notation embedded in Racket



On Apr 23, 2015, at 12:51 PM, Jos Koot  wrote:


Long ago I made various parsers (most of them in Fortran or assembler) for
expressions with infix notation. I always used push-down automata with two
or more stacks. Now I am playing with macros in Racket that allow infix
notation embedded in Racket without explicitly using push-down automata.
However, I encounter a contradiction in my desires as explained below. 


I have looked at 'Infix expressions for PLT Scheme' available in planet and
made by Jens Axel Søgaard. In his approach a+b is evaluated as though
written as (+ a b). However:
 
#lang at-exp scheme
(require (planet soegaard/infix))
(define a+b 4)
(define a 1) (define b 2)
@${a+b}  ; evaluates to 3
 
A Racket variable can contain characters such as +, -, * etc.
This makes @${a+b} confusing
(not necessarily ambiguous, though, depending on syntax and semantics.
 
In my own toy I require variables and operators to be separated by spaces.
So I write (infix b ^ 2 - 4 * a * c), not (infix b^2-4*a*c).
In my toy b^2-4*a*c is read as a single variable.


You might be interested in:
https://github.com/AlexKnauth/infix-macro
It does a similar thing, but with a more general way of defining operations
so that you can write something like:
#lang racket
(require infix/general-infix (for-syntax infix/general-infix-ct))
(define-infix-macro/infix-parser infix1
  (ops->parser add-op (unary-prefix-op #:sym 'sqrt #:id #'sqrt) expt-op))
(define-infix-macro/infix-parser infix2
  (ops->parser (unary-prefix-op #:sym 'sqrt #:id #'sqrt) add-op expt-op))
(infix1 sqrt 3 ^ 2 + 4 ^ 2) ; 19 ; equivalent to (+ (sqrt (expt 3 2)) (expt
4 2))
(infix2 sqrt 3 ^ 2 + 4 ^ 2) ; 5  ; equivalent to (sqrt (+ (expt 3 2) (expt 4
2)))


Of course notation b^2-4*a*c is attractive.


If you want that you could try looking at:
https://github.com/AlexKnauth/postfix-dot-notation
It provides two things.  One is a #lang postfix-dot-notation which is a
meta-language, and the other is a require-able module which provides
dot-notation by redefining #%top.
If you want to, you could start with either of these approaches to make
b^2-4*a*c (or even b^2-4ac) work.
Or I suppose you could also define an extension to
https://github.com/AlexKnauth/infix-macro that does this.


b ^ 2 - 4 * a * c looks rather ugly,
but allows unambiguous discrimination between operators and variables.
Furthermore my infix can be required within #lang racket.
It does not need at-exp.


What’s wrong with at-exp though?
I personally don’t like (planet soegaard/infix) as much mostly because the
other options have the benefit of working with DrRacket features such as
check-syntax arrows and blue-boxes, but that’s just because DrRacket is
awesome, not because at-exp is bad.  


(infix list('a, 'b ,'c)) and
(infix if(test, then-case, else-case))


Also you could look at this:
https://github.com/takikawa/sweet-racket



Even more attractive than b^2-4*a*c would be b^2-4ac,
but this would delimit variables to consist of one ch

Re: [racket-users] infix notation embedded in Racket

2015-04-23 Thread Alexander D. Knauth

On Apr 23, 2015, at 12:51 PM, Jos Koot  wrote:

> Long ago I made various parsers (most of them in Fortran or assembler) for 
> expressions with infix notation. I always used push-down automata with two or 
> more stacks. Now I am playing with macros in Racket that allow infix notation 
> embedded in Racket without explicitly using push-down automata. However, I 
> encounter a contradiction in my desires as explained below.

> I have looked at 'Infix expressions for PLT Scheme' available in planet and 
> made by Jens Axel Søgaard. In his approach a+b is evaluated as though written 
> as (+ a b). However:
>  
> #lang at-exp scheme
> (require (planet soegaard/infix))
> (define a+b 4)
> (define a 1) (define b 2)
> @${a+b}  ; evaluates to 3
>  
> A Racket variable can contain characters such as +, -, * etc.
> This makes @${a+b} confusing
> (not necessarily ambiguous, though, depending on syntax and semantics.
>  
> In my own toy I require variables and operators to be separated by spaces.
> So I write (infix b ^ 2 - 4 * a * c), not (infix b^2-4*a*c).
> In my toy b^2-4*a*c is read as a single variable.

You might be interested in:
https://github.com/AlexKnauth/infix-macro
It does a similar thing, but with a more general way of defining operations so 
that you can write something like:
#lang racket
(require infix/general-infix (for-syntax infix/general-infix-ct))
(define-infix-macro/infix-parser infix1
  (ops->parser add-op (unary-prefix-op #:sym 'sqrt #:id #'sqrt) expt-op))
(define-infix-macro/infix-parser infix2
  (ops->parser (unary-prefix-op #:sym 'sqrt #:id #'sqrt) add-op expt-op))
(infix1 sqrt 3 ^ 2 + 4 ^ 2) ; 19 ; equivalent to (+ (sqrt (expt 3 2)) (expt 4 
2))
(infix2 sqrt 3 ^ 2 + 4 ^ 2) ; 5  ; equivalent to (sqrt (+ (expt 3 2) (expt 4 
2)))

> Of course notation b^2-4*a*c is attractive.

If you want that you could try looking at:
https://github.com/AlexKnauth/postfix-dot-notation
It provides two things.  One is a #lang postfix-dot-notation which is a 
meta-language, and the other is a require-able module which provides 
dot-notation by redefining #%top.
If you want to, you could start with either of these approaches to make 
b^2-4*a*c (or even b^2-4ac) work.
Or I suppose you could also define an extension to 
https://github.com/AlexKnauth/infix-macro that does this.

> b ^ 2 - 4 * a * c looks rather ugly,
> but allows unambiguous discrimination between operators and variables.
> Furthermore my infix can be required within #lang racket.
> It does not need at-exp.

What’s wrong with at-exp though?
I personally don’t like (planet soegaard/infix) as much mostly because the 
other options have the benefit of working with DrRacket features such as 
check-syntax arrows and blue-boxes, but that’s just because DrRacket is 
awesome, not because at-exp is bad.  

> (infix list('a, 'b ,'c)) and
> (infix if(test, then-case, else-case))

Also you could look at this:
https://github.com/takikawa/sweet-racket

> Even more attractive than b^2-4*a*c would be b^2-4ac,
> but this would delimit variables to consist of one character only.
>  
> On one hand I want an attractive notation. On the other hand I want easy 
> embedding in Racket allowing the use of Racket variables in my infix 
> expressions
> and allowing renames of operators.

I can understand why you would want to use racket variables that might include 
+, or especially -, *, or / (!), but is there a reason why you would want to be 
able to rename operators by (require (only-in racket/base [+ plus]))? 

I can understand the need to define a new infix operator, which is what 
https://github.com/AlexKnauth/infix-macro does, or the desire to throw away 
precedence and order of operations to be able to use any identifier as an infix 
operator, which is what https://github.com/takikawa/sweet-racket does.

> The two hands contradict each other.

It seems to me like there are two problems here, or two contradictions:
First: racket identifiers with +, -, *, and / in them, versus math expressions 
without spaces
Second: generality of operators versus order of operations and precedence
Both of these are mainly about generality versus special-case convenience.  

For the first issue:
(planet soegaard/infix) takes the side of math expressions without spaces, but 
creates a clear separation between what follows racket’s rules and that follows 
math-expression rules.  This is nice because it provides both worlds without 
trying to mix them up in a weird way. 
Your infix macro, my infix macro, and sweet-exp all take the side of racket 
identifiers, which allow it to be much more general, but can make it look a 
little uglier.
One possible middle-ground here is to use #%top so that it only tries to use 
infix when it finds an identifier that would otherwise be undefined, but that’s 
conceptually more confusing. 

For the second issue:
Mathematical notation is not very general at all.
(planet soegaard/infix) takes the side of precedence, while, as far as I know, 
not allowing d