Skip to main content
gamedev.net
🔒 Locked

A simple scripting language idea.

Started by Nice Coder 12 replies 2.1k views
Original Post
Nice Coder
Nice Coder
Basically, its a lispish dialect, its just a much simpler version. Everything is interprited. (i'm not sure how on earth you would manage to compile it. jit maybe but not actualy compiling.) Everything is changable (you can make a function that changes. You can make new functions, remove functions, make and remove macros, ect.) For eg. (from what i've learned of lisp). Also, everything is called the same way, and it is treated the same. For eg: There are no functions. They are simply variables which you call with arguments. (and then in the actual variable code, they use the list 'args' which are all of these arguments). There are also no fixed macros. You can make, modify or deleate a macro at any time. Basically [square brackets] means that its a variable, and is replaced when seen by the interpriter with the variable, function, macro, ect. So, (set ([My_function]), ([Some_other_variable])) Would change the function my_function to Some_other_variable. Similarly, you can make and change macros. (Macro (The ship), (Ship1.ship)) There are no ""'s for strings. Everything is the same. Everything is a string, which is the same as code, and can be replaced with variables. (would come in handy, eh?) For eg, if your making a prime-finder (not that you'd actually use it), it would go somewhat like this:

(defun (Isprime, ([x])),
((for ([x]), (0), ((sqr ([y]))),
((if (mod (x), (y)), (0)),
(ifeq (Exit (2)))),
(print ([x] Is prime)))
The if is similar to a cmp in asm. It basically sets flags for things like ifeq, ifneq, ect. to use. Exit (2) basically means, (move 2 brackets up), which moves it up out of the piece of code that we have, and further along). See how elegant this is?

pubic function isprime(x as integer)
for x = 0 to sqr(y) step 1
if x % y = 0 then
   exit function
end if
next for
print x & " is prime"
end function
The lispish code (Ascript), just seems elegant. (and i only came up with the language idea a few days ago!). Also Ascript would be very easy to add oo features to. (because everything is the same. Objects would have to be a little different. And that wouldn't be too good...) So now, if you wanted to print of the arguments of a function, you would have your function (Set ([myfunc]), ( (while (not (emptylist (Args))), ( (print (pop (args)))) Which seems very elegant to me. You can also get individual elements from the args list, by simply going (Set ([x]), (element (args), (2))) ect. Which would lend itself to a nice little macro for setting up arguments as you like them. For eg. (Doargs (args), ([x], [y], [z], [theta])) Which would just be too simple to be considered a challange! What do you think of this? From, Nice coder [Edited by - Nice Coder on March 24, 2005 4:50:40 PM]
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
Nice Coder
Nice Coder
RE: Made modifications to post.

What do you think about this nice little scripting language?

Just for fun (coding in this is pretty fun), the doargs macro.

((set ([Doargsmacro]), ((For ([x]), (0), (len (args(1)))), ((set (element (args(1)), ([x])),(element (args(0), ([x]))))),(Defmacro (Doargs), ([Doargsmacro]))


Which you can't actually (easilly) translate into C++ code.

From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
Nice Coder
Nice Coder
All these views and not one reply?

From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
Nice Coder
Nice Coder
TTT in Ascript.

(set (main), ((while ([continue]), (False), ((while ([win]), (False) ((input ([move])),(set ([board{move}]), ([player])(if ([player], (P1)),(ifeq (Set ([player]), (P2))),(ifneq (Set ([player]), (P1))),(printboard ([board])),(Set ([win]), (Checkforwin ([board]))),)(print (Do you want to play again?)),(input ([continue]))))


That should probably be redesigned.
Now all i need are one function for printboard, and one for checkforwin.

Those are mainly going to be doing array equals, which would need a function.

I can see a small problem in the if's thens.... Maybe have a normal if operator
(Which just takes one argument and goes through if its true), then the ifgth, ect. (if you put in another argument) ?

From,
Nice coder

Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
Drew_Benton
Drew_Benton
Well I think this would be a nice idea - but then comes the part of implementation. If you could find a way to do this, then I think people would be interested in it. I mean right now I am working with an idea that I know how i want it to be, but implementing it is just a bit tad bit harder than I thought it would. So you'd better start coding! [wink]

As for the design of your simple script language, I think it is really do able, but to be of what use? I mean even if it is interpreted, how will people use it in their programs? It needs some easy interface to be binded to C/C++/Java/etc... in order to be effective.

Right now from my idea as well as many suggestions that have been made, I am thinking about a good way to make my own scripting language, for fun and the challenge. I do not have any experience with scripting languages yet so I can't compare your idea to what's out there, but I do know that I can think of a way this could be done in C++ (just lots of parsing [lol]).

Remember that (IMO) a scripting language should not be a replacement to do something in a programming language, just a means of doing it faster, more flexible, and simply. So, good idea, but I think a little more work would have to be done with implementation rather than concept.
flangazor
flangazor
You seemed to have missed the point of Lisp. You begin with an example using mutation - something functional programmers avoid. Most people us Lisp in a mostly functional manner.

Why do you need those commas? If you are using a parentheses delimited language, you shouldn't need commas anywhere (apart from un-quoting).

Having if being the same as cmp in asm implies you are going to do away with the entire type lattice of Lisp. Why?

If you're interested in a simple version of Lisp, I suggest you look into Scheme. When you're done with SICP and see any problems, then I suggest you start designing your language then.
Nice Coder
Nice Coder
Basically, what i would like to see this turn into, is a very simple to use, and simple to code language.

Drew- This would be one of the simplest languuages to write an interpriter for. There is little to do. You simply start at the first line, the innermost bracket, look up the symbol tables for functions and macros, then you execute the function (which is always at teh same spot).

There is no added punctuation. (the commas are used as list seperators.)

The actual program is just a large list.

flangazor - Yes. (not that i know what that is....)

I've been thinking, why do lisp programmers use functional programming instead of deterministic programming?

(difference is, that deterministic programming always does the same things given the same input. For eg. The prime checker egsample. That is deterministic.)

I've actually thought about making the language interpriter into a little activex dll. (little, because, well theres not much to actually do). So you can use it in basically everything. (C++, vb, ect.)

So, you basically set up a function table, and when the program calls that function, then it adds the function called and the args list to a larger list.
Every so often, you check that list to see if anything major happened. (this, because its a whole lot easier then tryping to make interupts.)

I'm actually thinking of this, because it seems simpler to understand.
Because everything is a list. All there are are brackets and commas. No other punctuation. No switching from code to data mode. They are one.

For eg. A binary searching sqrare root routine. Written in ascript.

(set ([BinarySqrt]), ((doargs (args), ([max], [min], [number])),(set ([Tmpvar]), (div ((sub ([max]), ([min])), (2))),(if ((sqrare ([Tmpvar]))), ([number])),(ifgth ((return (BinarySqrt([Tmpvar], [min], [number])))),(iflth ((return (BinarySqrt([max], [tmpvar], [number])))),(return ([tmpvar]))


I know, i'm not too good at lisp coding. But it still seems strange. (maybe i'm not used to lisp?)

Compared to
Public function binarysqrt(max as double, min as double, number as double)Tmpvar = (max - min) / 2if square(tmpvar) > number then   Binarysqrt = binarysqrt(tmpvar, min, number)elseif sqrare(tmpvar) < number then   Binarysqrt = binarysqrt(max, tmpvar, number)else   Binarysqrt = tmpvarend ifend function


Now, if you want to change that routine, you just have to change the variable. (you can't make new functions in vb...)

Major reson why i use ifs like the cmp in asm, is that i can do
(if (x), (y)),
(ifgth (do something,)
(iflth (do something else),

It just seems to fit the idea.

From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
Nice Coder
Nice Coder
Quote:
Original post by flangazor
You seemed to have missed the point of Lisp. You begin with an example using mutation - something functional programmers avoid. Most people us Lisp in a mostly functional manner.

Why do you need those commas? If you are using a parentheses delimited language, you shouldn't need commas anywhere (apart from un-quoting).

Having if being the same as cmp in asm implies you are going to do away with the entire type lattice of Lisp. Why?

If you're interested in a simple version of Lisp, I suggest you look into Scheme. When you're done with SICP and see any problems, then I suggest you start designing your language then.


Scheme seems.... awkward to program with.

From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
flangazor
flangazor
What makes you think Scheme is awkward?
The Reindeer Effect
The Reindeer Effect
Scheme isn't all that bad to program in IF you use existing libraries. If you are developing from scratch than things probably get tedious. Use something like mzLib and you can get down to business. It even comes with a decent object system, better than the other Scheme object systems I have seen.

Stolen from PLT's documentation.
define stack<%> (interface () push! pop! none?))(define stack%   (class* object% (stack<%>)    ; Declare public methods:    (public push! pop! none? print-name)        (define stack null)        ; A private field         (init-field (name 'stack)) ; A public field    ; Method implementations:    (define (push! v) (set! stack (cons v stack)))    (define (pop!)      (let ([v (car stack)])          (set! stack (cdr stack))          v))    (define (none?) (null? stack))    (define (print-name) (display name) (newline))    ; Call superclass initializer:    (super-new)))


It also gives you a few different ways to do things, so you can deal with methods like you would in C++ (public* (meth1 exrp) (meth2 expr)...) or java, where access modifier goes before every method declaration (define/public meth1 expr). The only thing that might weird people out is usage:

(define instance (new stack%));pushes 'cool onto the stack(send instance push 'cool)


You also can take advantage of the "this" idiom that we so love.

With the exception of call/cc, Scheme is JUST as easy to understand as CLisp. And once you understand continuations, things seem even nicer than you thought. Imagine the "try/catch" blocks in many languages as one instance of this idiom. And return statements. And break, continue, etc.
flangazor
flangazor
The Reindeer Effect, Continuations have some uses that make it more powerful than many might have first realized. Here are some papers using continuations in ways not limited to try-catch blocks:
Continuation Passing style
Quote:
CPS also lets you to represent first class continuations with FirstClassFunctions (because that is what they are in CPS). First class continuations can be used to implement exceptions, coroutines, threads, generator functions, CallWithCurrentContinuation, and all kinds of other constructs, some of which are quite esoteric.

Virtual Threads (pdf) (CPS giving massive speedups over POSIX threads - meaning threading isn't something to avoid unless nessesary).
Nice Coder
Nice Coder
Quote:
Original post by Anonymous Poster
Quote:
Original post by Nice Coder


(defun (Isprime, ([x])),
((for ([x]), (0), ((sqr ([y]))),
((if (mod (x), (y)), (0)),
(ifeq (Exit (2)))),
(print ([x] Is prime)))





Is there any way to lose the commas and the extra parens ???

Regular lisp is ugly enuf .....

The position/context of the atoms/params should be enough to parse and apply them.


Not really.
Lisp is nice. Don´t go taking it out of lisp.....
Brackets + commas == Only punctuation.
There are no differences, no complex sintax.(ha ha a pun).
Much easier to learn, and it will be very easy to use. (with a good ide. Assuming you code the right way. Bottom up programming, woo!)

Also:
Enough != enuf

From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
mumpo
mumpo
Quote:
Original post by Anonymous Poster
Quote:
Original post by Nice Coder


(defun (Isprime, ([x])),
((for ([x]), (0), ((sqr ([y]))),
((if (mod (x), (y)), (0)),
(ifeq (Exit (2)))),
(print ([x] Is prime)))





Is there any way to lose the commas and the extra parens ???

Regular lisp is ugly enuf .....

The position/context of the atoms/params should be enough to parse and apply them.

I second that.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.