www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - c++ vs lisp -- D perspective

reply Graham Fawcett <fawcett uwindsor.ca> writes:
Hi folks,

I just read a provocative critique of a blog article comparing C++ to 
Lisp:

http://funcall.blogspot.com/2010/05/c-vs-lisp.html

I've enjoyed using Lisp languages in the past, and appreciate that D 
offers a lot of metaprogramming features that could probably result in a 
cleaner, shorter equivalent than the worked C++ example in the articles.

Not looking for any language wars here: I just thought someone might 
enjoy discussing features of D that put it ahead of C++ in this type of 
programming.

Best,
Graham
May 04 2010
next sibling parent Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
On 05/04/2010 03:32 PM, Graham Fawcett wrote:
 Hi folks,

 I just read a provocative critique of a blog article comparing C++ to
 Lisp:

 http://funcall.blogspot.com/2010/05/c-vs-lisp.html

 I've enjoyed using Lisp languages in the past, and appreciate that D
 offers a lot of metaprogramming features that could probably result in a
 cleaner, shorter equivalent than the worked C++ example in the articles.

 Not looking for any language wars here: I just thought someone might
 enjoy discussing features of D that put it ahead of C++ in this type of
 programming.

 Best,
 Graham
(format t "~A { ~A }~%" num (reverse words)) could be translated to writefln("%s { %s }", num, retro(words)); except it seems like writefln doesn't actually print out the contents of an arbitrary range. Personally, I much prefer d to lisp regarding hash tables, and I think d's ranges is a cleaner abstraction than whatever lisp has or doesn't have. I do miss lisp's macros when programming in d, though. Sometimes template or string mixins do the job well enough, sometimes they don't. Things like reduce!("f(a) > b")(range), where f isn't defined in std.algorithm, or it's defined as something else (does this actually happen?)
May 04 2010
prev sibling parent bearophile <bearophileHUGS lycos.com> writes:
Graham Fawcett:
 I just read a provocative critique of a blog article comparing C++ to 
 Lisp:
 http://funcall.blogspot.com/2010/05/c-vs-lisp.html
Three years ago I have written this, for D1 with Phobos that doesn't use my dlibs1: import std.stdio, std.stream, std.string, std.ctype, std.gc; void traduct(char[] n, char[] digits, int start, char[][] words, char[][][char[]] gdict) { if (start >= digits.length) writefln(n, ": ", words.join(" ")); else { auto found_word = false; for(auto i = start; i < digits.length; i++) if (digits[start .. i+1] in gdict) { found_word = true; foreach(hit; gdict[digits[start .. i+1]]) traduct(n, digits, i+1, words ~ [hit], gdict); } if (!found_word && (!words || (words && !std.ctype.isdigit(words[words.length-1][0])))) traduct(n, digits, start+1, words ~ [digits[start..start+1]], gdict); } } void main() { std.gc.disable(); // to speed up the program a bit auto gtable = maketrans("ejnqrwxdsyftamcivbkulopghzEJNQRWXDSYFTAMCIVBKULOPGHZ", "0111222333445566677788899901112223334455666777888999"); char[][][char[]] gdict; foreach(char[] w; new BufferedFile("dictionary.txt")) gdict[w.translate(gtable, "\"")] ~= w.dup; foreach(char[] n; new BufferedFile("input.txt")) traduct(n, n.removechars("/-"), 0, [], gdict); } I think it's good enough compared to the Lisp version. I think it's better on the version of this program that was in the Digitalmars site. Bye, bearophile
May 05 2010