Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functions & Macros #211

Closed
noio opened this issue Dec 3, 2013 · 5 comments
Closed

Functions & Macros #211

noio opened this issue Dec 3, 2013 · 5 comments

Comments

@noio
Copy link
Contributor

noio commented Dec 3, 2013

Allow the user to define functions and shorthands for calling those functions. The functions could be shared through a mechanism like #212.

1) Functions

Create syntax for defining functions that can take a code block as an argument. Like

grid(3, 4, <code>)

for

4.times (x) ->
  3.times (y) ->
    pushMatrix
    move (-(4-1)/2+x),(-(3-1)/2+y),0
    //--
    <code>
    //--
    popMatrix

2) Macros

Letting users define rewrite rules that make these functions easier to write:

3 x 4
  <code> 
// rewritten to
grid(3, 4, <code>)
@rumblesan
Copy link
Collaborator

so one of the things that I still want to have available in LiveCodeLang is first class functions and higher order functions. this would make it easy to have functions like the grid one above. This is currently how the times loop actually works.

At the moment I'm making live code lang very basic because I still need to get to grips with this language design stuff first, but extending it should be reasonably easy once everything is done.

Macros are something I'm less sure about. I think they can be powerful, but I'd rather look at other ways of creating that sort of functionality using higher order functions and language features. Ongoing discussion I guess

@davidedc
Copy link
Owner

davidedc commented Dec 3, 2013

  1. can be done this way, is this what you have in mind?
grid = (columns,rows,code) ->
    for x in [1..columns]
        for y in [1..rows]
            pushMatrix
            move (-(4-1)/2+x),(-(3-1)/2+y),0
            code()
            popMatrix

grid 3,2,->
    rotate box
    move ball

I think that we could simplify the notation of grid 3,2,-> into grid 3,2. In fact I think we could also safely simplify that code() into code if we wanted to.

  1. I'm so deep in non-macro aspects of the language so far that I don't have a view on macros yet. In principle, why not, but I'd probably need some more time to have a good opinion about them.

@noio
Copy link
Contributor Author

noio commented Dec 3, 2013

Oh, actually, that is exactly what I had in mind. Nice! I just didn't know how easy it was to pass a code block by creating an anonymous function with -> (Even though I was doing it with times 😅 ). As far as I'm concerned that completely obviates the need for macros.

So this feature is in LCL and I just didn't know it, so feel free to close ☑️

@davidedc
Copy link
Owner

davidedc commented Dec 3, 2013

closing. macros are outstanding but maybe we can live a bit more with just what we have.

@davidedc davidedc closed this as completed Dec 3, 2013
@rumblesan
Copy link
Collaborator

higher order functions solve everything! or maybe I've just been coding scala and haskell too long...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants