Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Yet Another Language to Check Out
Index -> General Programming
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
wtd




PostPosted: Fri Sep 30, 2005 11:42 pm   Post subject: Yet Another Language to Check Out

http://www.opendylan.org/learning.phtml
Sponsor
Sponsor
Sponsor
sponsor
Hikaru79




PostPosted: Fri Sep 30, 2005 11:55 pm   Post subject: (No subject)

Am I doing something wrong with the compiler here? I took the d2c compiler that Ubuntu has in its repos. I wrote a simple Hello, world:
code:
module: hello

format-out("Hello, World!\n");
And then I ran:
code:
hikaru79@ubuntu:~/Programming/Dylan$ d2c hello.dylan
And from what I can tell, it automatically generated a hello.c file, which it then simply compiled as a C program. Now, here's the kicker: the hello.c file it generated is 51,235 lines long, at 2.0 megabytes! The executable is 444kb. Now, I'm no ricer, but this seems a bit excessive. Is this normal? Have you tried the other compiler, OpenDylan?
wtd




PostPosted: Sat Oct 01, 2005 1:10 am   Post subject: (No subject)

Try writing a less trivial program.

code:
module: hello

define class <greeter> (<object>)
   slot name :: <string>, required-init-keyword: name:;
end;

define method greet(g :: <greeter>, other-name :: <string>) => ()
   format-out("Hi %s!  I'm %s\n", other-name, g.name);
end method;

let me = make(<greeter>, name: "Bob");

greet(me, "John");


Nearly the same generated executable size.

We can fairly safely surmise that the bulk of the Hello world program was boilerplate that ends up in any program. More complex programs may not be expected to grow linearly.
Hikaru79




PostPosted: Sat Oct 01, 2005 9:32 am   Post subject: (No subject)

Ah, yes, I see. I guess the first 2 megs are just overhead that Dylan creates.
wtd




PostPosted: Sat Oct 01, 2005 11:55 am   Post subject: (No subject)

Keep in mind that the Dylan language does a lot of things that C and even C++ do not.
rizzix




PostPosted: Sat Oct 01, 2005 1:05 pm   Post subject: (No subject)

ah a prototyping language... like Self.. oh well.. they did pick the worst name ever though.. sheesh "dylan".
wtd




PostPosted: Sat Oct 01, 2005 1:18 pm   Post subject: (No subject)

If I may ask... where do you get that it's a prototype-based language?
rizzix




PostPosted: Sat Oct 01, 2005 1:21 pm   Post subject: (No subject)

oh... i blindly assumed that.. hmm considering the "slots" and stuff.. correct me if i'm wrong.. hmm
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Sat Oct 01, 2005 1:25 pm   Post subject: (No subject)

The language is essentially Lisp in a vaguely Wirth-ish syntax. The terminology is taken from CLOS.
wtd




PostPosted: Sun Oct 02, 2005 4:24 am   Post subject: (No subject)

A TYS for Dylan. Smile

I have the following code:

code:
module: name-test

define class <name> (<object>)
   slot first-name :: <string>,
      required-init-keyword: first:;
   slot last-name :: <string>,
      required-init-keyword: last:;
end class <name>;

define method full-name(name :: <name>) => output :: <string>;
   concatenate(name.first-name, " ", name.last-name);
end method full-name;

define method print-name(name :: <name>) => ();
   format-out("%s\n", full-name(name));
end method print-name;

define variable *a-name* = make(<name>, first: "Bob", last: "Smith");

print-name(*a-name*);


Now that works quite logically, the way you'd expect.

What if I insert the following?

code:
*a-name*.first-name := "";


Now the output looks weird. So, how do I still allow that assignment, but disregard any attempt to assign an empty string to either the first or last name?
wtd




PostPosted: Tue Oct 04, 2005 8:19 pm   Post subject: (No subject)

I'm spoiled by Ruby code like:

code:
10.times do |i|
   puts i
end


Ruby's blocks make all kinds of clever looping schemes possible.

So I wanted to write something like this in Dylan. Dylan doesn't have the same mechanism as Ruby, though, and has no built-in loop of this type. I'm out of luck, right?

Not quite. I was able to compile this:

code:
times 10 with i
   format-out("%d\n", i);
end times;


So, how was this possible?

Well, I had to write a macro.

code:
module: macro-test

define macro times
   { times ?num:expression with ?var:variable ?:body end }
   =>
   {
      let ?var = 0;
      while (?var < ?num)
         ?body;
         ?var := ?var + 1;
      end while;
   }
end macro times;


But, then I realized I might instead want a simpler loop, without the variable.

code:
times 10
   format-out("Hello\n");
end times;


So I created another syntax rule for the macro.

code:
module: macro-test

define macro times
   { times ?num:expression with ?var:variable ?:body end }
   =>
   {
      let ?var = 0;
      while (?var < ?num)
         ?body;
         ?var := ?var + 1;
      end while;
   }

   { times ?num:expression ?:body end }
   =>
   {
      let var = 0;
      while (var < ?num)
         ?body;
         var := var + 1;
      end while;
   }
end macro times;


Then I created a bunch of other variants. Smile

code:
module: macro-test

define macro times
   { times ?num:expression with ?var:variable ?:body end }
   =>
   {
      let ?var = 0;
      while (?var < ?num)
         ?body;
         ?var := ?var + 1;
      end while;
   }

   { times ?num:expression ?:body end }
   =>
   {
      let var = 0;
      while (var < ?num)
         ?body;
         var := var + 1;
      end while;
   }

   { times ?num:expression with ?var:variable from ?f:expression ?:body end }
   =>
   {
      let ?var = ?f;
      while (?var < ?num + ?f)
         ?body;
         ?var := ?var + 1;
      end while;
   }

   { times ?num:expression with ?var:variable from ?f:expression by ?b:expression ?:body end }
   =>
   {
      let ?var = ?f;
      while (if (?b >= 0) ?var < ?num * ?b + ?f else ?var > ?num * ?b + ?f end)
         ?body;
         ?var := ?var + ?b;
      end while;
   }

   { times ?num:expression with ?var:variable by ?b:expression ?:body end }
   =>
   {
      let ?var = if (?b >= 0) 0 else -?b * (?num - 1) end;
      while (if (?b >= 0) ?var < ?num * ?b else ?var >= 0 end)
         ?body;
         ?var := ?var + ?b;
      end while;
   }
end macro times;


Dylan's macros rock.
rizzix




PostPosted: Tue Oct 04, 2005 9:15 pm   Post subject: (No subject)

seems kinda pointless.. to write all that code for something so simple.
wtd




PostPosted: Tue Oct 04, 2005 9:46 pm   Post subject: (No subject)

It makes the code more expressive.

http://www.gwydiondylan.org/books/dpg/db_334.html
Display posts from previous:   
   Index -> General Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 13 Posts ]
Jump to:   


Style:  
Search: