low-level approach

Brian P Templeton bpt@tunes.org
Tue Jan 15 16:49:01 2002

Kyle Lahnakoski <kyle@arcavia.com> writes:

> Ulrich Hobelmann wrote:
>> Kyle Lahnakoski wrote:
>> > For example, the difference between C and Java can be summed in three
>> > aspects:
>> >         Java has garbage collection
>> >         Java has inheritance (limited polymorphism)
>> >         C has function pointers
>> I'd claim that Lisp first class functions are way more powerful than C
>> fun-pointers in that they capture an environment.
> Maybe you would be so nice as to provide an example where the "powerful"
> aspect of first class functions shows itself by shortening code length
> or reducing development time.
>> (BTW: can anyone tell me in what way Java's inheritance doesn't
>> correctly
>> model subtyping? this was hinted at in the TUNES-glossary->Inheritance
>> ... ?)
> See my document
> http://www.arcavia.com/rd/document/Function%20Inheritence.htm
>> I think the point here is that the C type system is _very_ weak, and
>> there's
>> no safety or GC, so writing List code is very bug-prone compared to
>> Lisp.
> I will grant that C is bug prone, but in the same note I am unsure how
> safe Lisp is.  It strikes me that Lisp lacks type information; I am able
> to pass anything I want to a Lisp function and it will not complain
> unless it runs out of symbols.  I could certainly be wrong here.
Yes, you are, in this case. Common Lisp has, IMHO, a very useful
typesystem, and by using defmethod, you can specialize generic
functions on their argument types:

--- lisp-mode ---
;; This could be changed to a (probably clearer in this case)
(defmethod foo ((x string))
  (format t "~&Got a string~%"))
(defmethod foo ((x number))
  (format t "~&Got a number~%"))
(defmethod foo ((x cons))
  (format t "~&Got a cons~%"))
;; and later... (after you've tried those to convince yourself that it
;; does check the types)
(defmethod foo ((x t))
  (format t "~&I'm not sure what I got, but at least it has a type!~%"))
--- end lisp-mode ---

BTW, DEFMETHOD was invented to make CLOS hacking easier; however, it's
useful for other purposes, too, since CLOS is fully integrated with
the typesystem.

Also see the standard Common Lisp CHECK-TYPE function if you don't
want to define lots of generic functions.

> In any case, I think we both agree that strong typing helps reduce
> development time by reducing human error.
>> Also, in general, most Lisps have other types like vectors and records.
> I have only seen these implemented using lists.  Maybe there are Lisp
> versions that implement these natively.
Yes, every CL implementation that I've ever heard of for vectors, and
for structures (as was pointed out elsewhere in this thread) you can
choose between several different implementations, the default being to
use a metaclass.

>> Other Lambda-based languages like Haskell/ML use these other types much
>> more than lists...
> So would you consider this a good thing?
>> To me the bad point about Java is that in Lisp you can have Objects or
>> structs,
>> while in Java, expressing functions (via interfaces..) is sooo ugly...
>> (Hmmm... wasn't Java developed by James Gosling and Guy Steele, two
>> Lispers???)
> Yes, certainly a deficiency in Java.
>> Usually, when you directly translate C into Lisp, you immediately
>> notice several points which need improvement, because C code is more
>> bound to restictions in language comfort, which Lisp is more free-form
>> and doesn't restrict you in any way.
> Maybe your direct translation of the C code is because of poorly written
> C code.  Do you have an example?  If you prefer to wait until next time
> you stumble cross the scenario you describe above, send it to me then. 
> I will remember this conversation; it has bothered me for years. 
>> You can even implement your own syntax macros.
> How would you say these macros are better than including a compiler
> library to C, if at all?
> I would love to deliver examples of Lisp and C to show they are very
> similar, but any example I come up will be disputed as contrived.  An
> example can only prove my premise false.  Unfortunately I can not think
> of one because I believe an example does not exist.
> Thanks

BPT <bpt@tunes.org>	    		/"\ ASCII Ribbon Campaign
backronym for Linux:			\ / No HTML or RTF in mail
	Linux Is Not Unix			 X  No MS-Word in mail
Meme plague ;)   --------->		/ \ Respect Open Standards