Re: Let me try once more

new topic     » goto parent     » topic index » view thread      » older message » newer message

George Henry wrote:

> Sounds like I'm pushing Lisp, but all I'm saying
> is, there are perfectly good languages for doing
> what you propose, and unless/until Rob changes his
> mind about executing code-as-data, Euphoria isn't
> one of them.

Actually, Euphoria is an excellent language to implement a LISP-ish sort of
language in. Here's a simple (untested) example:


global constant
   LITERAL = 0,
   ADD = 1,
   PRINT = 2

function eval( sequence code )

   integer op
   op = code[1]

   if op = LITERAL then
      return code[2]
   elsif op = ADD then
      return eval( code[2] ) + eval( code[3] )
   elsif op = PRINT then
      ? eval( code[2] )
      return 1
   else
      printf( 1. "Unknown opcode %d\n", {op} )
      abort(0)
   end if

end function

And here's a call to the eval function:

   object result
   result = eval( { PRINT, { ADD, { LITERAL, 1 }, { LITERAL, 1 } } }

Looks awfully LISP-ish to me. Replace the if/then/else calls with indexed
calls to call_proc, add a parser on the front of it, and you've got your own
custom programming language.

That's exactly what I did with Eu and Py.

-- David Cuny

____________________________________________________________
T O P I C A  -- Learn More. Surf Less. 
Newsletters, Tips and Discussions on Topics You Choose.
http://www.topica.com/partner/tag01

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu