Ai Dreams Forum

AI Dreams => General Chat => Topic started by: Zero on September 18, 2018, 10:13:52 am

Title: Good language for metaprogramming?
Post by: Zero on September 18, 2018, 10:13:52 am
What programming language has good metaprogramming capabilities in your opinion?
(Preferably not s-exp based ;) )
Title: Re: Good language for metaprogramming?
Post by: ivan.moony on September 18, 2018, 11:56:06 am
Javascript has that `eval` function that compiles a sring into code at runtime. And I thik assembler is a king of metaprogramming.
Title: Re: Good language for metaprogramming?
Post by: Zero on September 18, 2018, 02:24:58 pm
Yes, you can also retrieve the source code of a function, by calling its toString() method.
There's also Reflect and proxies... Javascript is not bad at all :)

Assembler? That's an unexpected answer! but I can see what you mean...
Title: Re: Good language for metaprogramming?
Post by: Ultron on September 20, 2018, 12:21:48 pm
I mentioned this previously however I concluded there is no interest on the topic. Check out my reply at

http://aidreams.co.uk/forum/index.php?topic=13359.msg54760;topicseen#new (http://aidreams.co.uk/forum/index.php?topic=13359.msg54760;topicseen#new)

I personally work with Javascript in various project with various requirements but would never use it for the discussed application.
Title: Re: Good language for metaprogramming?
Post by: Zero on September 20, 2018, 02:44:48 pm
... which makes Julia (http://aidreams.co.uk/forum/index.php?topic=13155.msg53374#msg53374) sexy again! Thanks for the link, I'll look into Julia's metaprogramming capabilities. :)
Title: Re: Good language for metaprogramming?
Post by: ranch vermin on September 21, 2018, 02:05:41 am
truth table masks.

//A B C  S  C
//0 0 0  0  0
//1 0 0  1  0
//0 1 0  1  0
//1 1 0  0  1
//0 0 1  1  0
//1 0 1  0  1
//0 1 1  0  1
//1 1 1  1  1

the output is just as much data as the input is.
Title: Re: Good language for metaprogramming?
Post by: Zero on September 21, 2018, 08:41:09 am
Homoiconicity is a funky thing. After all, every language has a source code made of strings, and every language can manipulate strings. However, closures are usually not accessible - as data - from the runtime.

In Javascript, I'd like a function to be able to refer to itself without knowing its own name. Before, there was "callee", but now you're supposed to give it a name and access it using its name, which is less powerful. They say it's because doing otherwise makes a lot of optimizations impossible.

You're maybe wondering the why of all this.

The other day, I was thinking about... some kind of world of functions. Building a system not as a whole, but rather as a landscape. You see Tron, the movie? There are programs running everywhere, living out their lives. I thought, what would it look like, for real?

Imagine a person is a Javascript function. There are two things we need first:
- It has to be currently "somewhere" geographically, and
- It has to move.

The "somewhere" is easy: some object, or some array (which are objects in Js) holds a reference to it. The landscape, so to speak, is an object, which has roots in "window" in the browser, or "global" in node.

It also has to move. So it must be executed, every now and then. There could be a "world scanner", that loops through every object, executing every function.

The closure of the function would represent its "mind". It is a part of a person that other persons cannot see.

It would have been neat to just call functions, and let them be able to access their own source code, to modify it when needed, but you can't in Javascript. So the simplest way to achieve this, is to call these persons-functions with an argument pointing to themselves (meaning these functions would have a "me" parameter). Their "this" would point to where they are, as usual.

That's a starting point.  :idiot2:
Title: Re: Good language for metaprogramming?
Post by: Korrelan on September 21, 2018, 10:17:48 am
It seems to me you are describing a type cellular automation (Conway’s Game Of Life).

Homoiconicity is not a native function of modern computers, therefore languages that can leverage Homoiconicity like Lisp where written in standard languages that can’t… if you get my drift.

My point being that even though Java does not have the functionality you require you can still write a language/ interpreter that does.

 :)
Title: Re: Good language for metaprogramming?
Post by: Zero on September 21, 2018, 11:00:26 am
Sure... I get it.

But there are Javascript parsers written in Javascript, and you can get the source code of a function using its toString() method, so it's not direct homoiconicity, but we're still dealing with code as data. Which is pretty cool!