The Nexus programming language has been released. It is an "object-oriented, dynamically-typed, reflective programming language", drawing from Lua and Ruby.
Nexus Programming Language
Started by mavatar, Jul 22 2009 02:41 AM
4 replies to this topic
#1
Posted 22 July 2009 - 02:41 AM
|
|
|
#2
Guest_Jordan_*
Posted 22 July 2009 - 02:43 AM
Guest_Jordan_*
Do you have an example code so we can see it in action?
#3
Posted 22 July 2009 - 02:50 AM
/**
* Object monitor signal/wait
*
* Demonstrates object monitor signal/wait thread synchronization.
*/
class Store
{
/**
* Put
*
* params: value
* return:
*/
public synchronized method put (value)
{
while (@available = true) {
try {
System.Concurrent.Monitor.wait(self)
;
print(last_excp())
}
}
value^@seq
true^@available
System.Concurrent.Monitor.signal(self)
}
/**
* Get
*
* params:
* return: value
*/
public synchronized method get ()
{
while (@available = false) {
try {
System.Concurrent.Monitor.wait(self)
;
print(last_excp())
}
}
false^@available
System.Concurrent.Monitor.signal(self)
@seq
}
/**
* Initialize
*
* params:
* return:
*/
method initialize ()
{
field @seq(0)
field @available(false)
}
}
class Producer
{
/**
* Run
*
* params:
* return:
*/
method run ()
{
for (i; 0..9) {
@store.put(i)
print("Producer #" + @id + " put: " + i)
System.sleep(System.random(0,9) * 10)
}
}
/**
* Start
*
* params:
* return: thread (Thread)
*/
public method start ()
{
System.Concurrent.Thread.new(get_method("run"))^thread.start(self)
// return
thread
}
/**
* Initialize
*
* params: id
* store
* return:
*/
method initialize (id, store)
{
field @id(id)
field @store(store)
}
}
class Consumer
{
/**
* Run
*
* params:
* return:
*/
method run ()
{
for (i; 0..9) {
@store.get()^value
print("Consumer #" + @id + " got: " + value)
}
}
/**
* Start
*
* params:
* return: thread (Thread)
*/
public method start ()
{
System.Concurrent.Thread.new(get_method("run"))^thread.start(self)
// return
thread
}
/**
* Initialize
*
* params: id
* store
* return:
*/
method initialize (id, store)
{
field @id(id)
field @store(store)
}
}
/**
* Main
*
* params:
* return:
*/
method main ()
{
Store.new()^store
Producer.new(1, store)^producer
Consumer.new(1, store)^consumer
Array.new()^threads
threads.add(producer.start())
threads.add(consumer.start())
// join threads
for (i,t; threads) {
t.join()
}
}
main()
Edited by Jordan, 23 July 2009 - 01:29 PM.
#4
Posted 22 July 2009 - 02:53 AM
nexuslang.org
#5
Guest_Jordan_*
Posted 23 July 2009 - 01:30 PM
Guest_Jordan_*
What is the primary purpose of the language?


Sign In
Create Account

Back to top









