Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Mexpr Scheme

Name: Anonymous 2012-10-27 11:11

Hello /prog/.
I'm making my own Scheme-like language with blackjack and hookers. It slowly became nearly as ugly as common lisp, so I decided to look through original McCarthy papers and implemented alternative syntax: http://pastebin.com/fiJKvvMY
New syntax causes new problems. The biggest problem bugging me now is method call syntax. Originally method call looked like (method object ...) where method is an expression which returns atom or an atom itself. This allows to choose method at run-time.
New syntax requires to write object #method[...] with method explicitly specified at compile-time. That looks like a problem to me.
Any ideas how to improve syntax?

Name: Anonymous 2012-10-27 11:37

Simple, just force the indentation of the code. It worked for Guido!

Name: Anonymous 2012-10-27 11:46

>>1
I remember this. I thought it would turn out ugly. Just use clos style dude! They mix wonderfully with the higher order functions.

But if you want to go with method invocations, you can think about the parse tree for the conventional languages:


obj.method1(arg1, arg2).method2(arg3)
((. ((. obj method1) arg1 arg2) method2) arg3)


Or you can think of obj as a function that takes symbols and returns functions


((((obj method1) arg1 arg2) method2) arg3)


Or you can think of obj as a function that takes a list of args where the first arg is the method to invoke, and the rest of the args are the arguments to the method:


((obj method1 arg1 arg2) method2 arg3)


Or you can just use clos style.


(method2 (method1 obj arg1 arg2) arg3)


The #method syntactic sugar works too, but you should just let it be syntactic sugar for one of the representations above so that you can still use the object system from macros in a painless way.

Name: Anonymous 2012-10-27 11:58

mexpr
Are you fucking out of your mind?

Name: Anonymous 2012-10-27 12:02

>>3
I do already use (nearly) clos-style method call in the base(sexpr) language, i.e.
(foo: bar args ...)
where "foo:" is an atom(or selector). The point is that I can write
((if foo foo: baz:) bar args ...)
in sexpr form to choose method dynamically, but can't write the same using new syntax. I have to write verbose
if[foo; bar#foo[args ...]; bar#baz[args ...]]
instead. In fact I still can write "{if[foo; #foo; #baz]; bar; args ...}" as list, but it is awful form.

Name: Anonymous 2012-10-27 12:06

>>4
Why? Mexprs are more readable. They considered incompatible with powerful macrosystem due to imaginary lack of homoiconicity, but in fact they could be better than sexprs.

Name: Anonymous 2012-10-27 12:07

>>5
how about supporting curried functions and having bar#foo be syntactic sugar for (foo bar)?

Name: >>7 2012-10-27 12:52

No, curried functions just don't mix with scheme. Too much emphasis on variable length arguments. How about:


(define (# object method)
  (lambda args
    (apply method (cons object args))))


and then a reader macro that translates


object#method


to


(# object method)

Name: Anonymous 2012-10-28 10:51

how do you access class/instance variables?

Name: Anonymous 2012-10-28 12:15

>>9
foo.bar => (bar foo)
foo.bar = baz => (bar foo baz)

It's perfect.

Don't change these.
Name: Email:
Entire Thread Thread List