Code Monkey home page Code Monkey logo

Comments (5)

lewismj avatar lewismj commented on August 16, 2024

Wouldn't you build those out of LISP itself, adding to your "prelude", don't think you need to bake those into the builtin's (though I'm sure it is possible).

from buildyourownlisp.

zmmaj avatar zmmaj commented on August 16, 2024

Ah.. I was try.. but without any progress. That is why I need help.. example or similar..
But, your post may help.. i think.
I will try something as you wrote.
(fun {do & l} {
if (== l nil)
{nil}
{last l}
})

that's smell as repeat() function eg. repeat number of times(function or calculation)
Problem is harder.. You see.. repeat function need to send output after every loop. while(), for() doing same...
whatever I wrote whenever my new function send output they broke self.
Your above function is OK.. they send out only last l .. but loop functions send's output after every loop.
how to wrote to resume on next loop without stopping self?
Sorry I am not expert in english. , I hope You will understand what is a problem.

from buildyourownlisp.

lewismj avatar lewismj commented on August 16, 2024

I'd query why you want a for/while/repeat, not being obtuse, but in general, I'd stick to map, fold and reduce functions for functional programming. e.g. in Scala, I don't think I've ever used a while loop....
That said, I think it is fairly fundamental that you don't (author can correct me if I'm wrong) implement those things in the C, rather the C is effectively a simple extended lambda-calculus engine of sorts, and the prelude should implement the higher level constructs. The builtin is I think supposed to be just enough for you to build a prelude in your language.

from buildyourownlisp.

zmmaj avatar zmmaj commented on August 16, 2024

I try to put these code on higher level...
I am game maker programmer.. A expert for older version of gamemaker from gm 4 to gm 8.1..
So, this can be interested 'cose GM studio 1 and 2 was very veeery slow while compile code.
Older version was been written in Python, now that is all ported to C++, and it's NOT GOOD. Too slow... not game.. compiling. For me as programmer that is horror...
To be short,
When you create eg sky with stars you will need repeat, or while, or similar instead to write codes for every star on sky.
I was import SDL codes here, and they works... Nothing big.. about 10-15 commands, but I was stop when I realise that I can't to do many things who are depend from loops.
eg, checking collision, positions etc,
That is not cruicial only for games..
So, if IS possible, please help me to make loop functions, built in, or external...
tnx in advance.

from buildyourownlisp.

zmmaj avatar zmmaj commented on August 16, 2024

Ok.. I was make built-in function REPEAT
I need While, for, etc etc loop functions

lval* builtin_repeat( lenv* e, lval* v) {
LASSERT_NUM("repeat", v, 2);
LASSERT_TYPE("repeat", v, 0, LVAL_NUM);
LASSERT_TYPE("repeat", v, 1, LVAL_QEXPR);
v->cell[1]->type = LVAL_SEXPR;
int broj= (int)v->cell[0]->num;
lval* res;
lval* x;
lval* y;
int i = 0;
lval* l[broj];
while (broj > i){
y= lval_copy(v);
res= lval_pop( y, 1);
x = lval_eval(e, res);
l[i] = x;
lval_println(x);
x=NULL;
y=NULL;
res=NULL;
i++;
}

lval_del(v);
return l[1];
}

USAGe
repeat 5{ print "aa"}
repeat 5{100}
repeat 10 { + 2 3}
etc etc
and YES.. I was make and function for random number.

from buildyourownlisp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.