Identifiers with dashes and the infix package

Hello,

Almost out of sheer curiosity, is there a way to use identifiers with dashes with the infix package, with or without at-exp?

I would like to be able to do something like this:

#lang at-exp racket
(require infix)
(define my-variable 3)
@${my-variable + 1}

Here is the error message I am getting:

; tmp.rkt:6:4: my: unbound identifier
;   in: my

From the error message I infer that the class of identifiers infix accepts does not allow dashes, because they are treated as subtraction. I read the sources a little bit, but I couldn't see whether there is a way to escape my-variable to make the above example work.

You can use an underscore in infix mode:

#lang at-exp racket
(require infix)
(define my-variable 3)
@${my_variable + 1}

It would be nice, if |my-variable| could be used. If you want to add that, look at infix/infix/parser.rkt at master · soegaard/infix · GitHub

1 Like

Oh, great, thanks @soegaard !

I did think of |my-variable| as well, so it might be a cool side project indeed. Unfortunately, given my current time constraints, somebody will probably get around to implementing that before I do :smiley:

As someone who enjoys whitespace as well as the liberal choice of characters for identifiers in lispy langs: I think another interesting design is to require space between most tokens.

In 1 + foo * 3, AFAICT there's no ambiguity to disallow foo being foo-bar, foo/bar, or even 1foo (as well as |any chars|), just like in Racket?

But that's probably not suitable for your existing infix library -- some people who prefer infix probably also like being able to minimize spaces and write things like 1+foo*3. :smile:

1 Like

I am just relieved that scolobb's identifier wasn't my-variable* :slight_smile:

Or my_variable for that matter.

So quoting with || would be a great addition.

2 Likes

@scolobb I updated infix today. Now the syntax |c*| where c is any non-pipe character can be used. Thanks for the impetus to make the change.

1 Like

That's amazing @soegaard , thank you very much!