Re: Another crazy new language effort - Language #42
- From: Bill Cox <xyzzybill@xxxxxxxxx>
- Date: Sun, 1 Feb 2009 03:17:46 -0800 (PST)
On Jan 31, 10:43 am, Robbert Haarman <comp.lang.m...@xxxxxxxxxxxxx>
wrote:
Bill,
In42, programmers wont need to templify their code to make it
reusable. I'm taking the opposite approach of keeping the internals
private and hidden. Instead, it's 'reuse' construct reads your source
code, makes changes, and remaps it to local data structures. There's
no concept of reuse of binary-only libraries, as in C++. On basic
data structures like doubly-linked lists, the reuse construct makes it
simpler to write because it can reuse code from the linked-list
package. Also, the next and prev pointers get embedded in the child
class where they belong.
Could you give an example of that in code?
Regards,
Bob
--
Duct tape is like the Force.
It has a light side, it has a dark side, and it holds the universe together.
Sure, although most of this is still in my head, and not yet
implemented. Any package is a template. Just declare it's reuse:
package LinkedList
class Parent
Child head
insert(Parent parent, Child child)
child.next = head
head = child
class Child
Child next
package DoublyLinkedList
reuse LinkedList
class Parent
Child tail
insert(Parent parent, Child child)
if parent.head != null
parent.head.prev = child
else
parent.tail = child
LinkedList.Parent.insert(child)
class Child
Child prev
In this case the Parent and Child classes aren't mapped to other
classes, but if they were, the reuse statement would specify how the
new packages classes contain an embedded sub-graph of the old packages
classes. In 42, the 'relationship' statement is just syntactic sugar
for 'reuse'. To declare a linked list between classes Foo and Bar,
you write:
relationship Foo Bar LinkedList
Which expands into:
reuse Foo Bar
Parent -> Foo
Child -> Bar
You can also do the Python style of code generation in 42, in that you
can write functions that are interpreted at compile time that add
properties and methods to classes, but not individual objects as in
Python. Relationships happen to use the 'reuse' construct, but if
more complex code manipulation is required, it's not hard to do. For
example, it's possible to write a package in 42 that provides infinite
undo/redo for any data structures. Even classes aren't part of Core
42 (the minimal subset of 42 that's directly translated to C and/or
Verilog). Classes are defined in a package. The compilation process
in 42 is a process where the built-in Core 42 interpreter runs the
code to be compiled through one package at a time (those that the code
imports). As each package executes, they reduce the code being
compiled to a simpler form which does not depend on the package. In
the end, the user's program is converted to the Core 42 subset, which
is then directly translated to C/Verilog.
The 'reuse' construct isn't actually a text replacement scheme.
Instead, the compile-time interpreter re-evaluates the old package,
with the reuse mapping applied to each line. Packages can take
compile-time parameters that customize how the package is
instantiated. However, this counts as "templifying' your code in my
book. I expect in 42 that it will be the end-users of packages that
add package parameters to an author's code. The language strongly
discourages binary-only reuse, and 42 programmers can expect access to
package source.
Regards, Bill - 42babel (a reasonable Google search word?)
.
- Prev by Date: Re: Cfront released in public domain at last
- Next by Date: Re: A taxonomy of types
- Previous by thread: Cfront released in public domain at last
- Next by thread: Re: Another crazy new language effort - Language #42
- Index(es):
Relevant Pages
|