It seems that sometimes code in functional programs accepts other code (functions) as arguments and modifies it and returns it for execution. It seems similar to self-modifying code. Does this mean that the compactness of functional programs result from the same reason that allows extremely compact self-modifying programs?
-
This is a neat question, but I think it's the kind of discussion question that just gets closed here. – Ernest Friedman-Hill Apr 13 '13 at 03:11
-
google "homoiconic language" – Gene T Apr 15 '13 at 10:46
-
can someone vote to reopen? i already tried – necromancer May 03 '13 at 02:52
1 Answers
Ernest Friedman-Hill may be correct that this question doesn't belong here, but here is an answer:
I would say: No.
There are various ways that a language can allow self-modifying code. The most flexible way would be to be able flip arbitrary bits at arbitrary locations in memory. (Here is a classic story: The Story of Mel.) But self-modifying methods need not exhibit such dangerous freedom. In Common Lisp, it's easy to write code that constructs Lisp code and the evaluates it, but this all stays within the constraints of Lisp, and it's not necessarily more compact. In Java, you can do certain kinds of "self-modification" using reflection, but this is often more verbose than regular Java usage.
Also, keep in mind that there's actually a fine line between some kinds of object-oriented methods and functional programming methods. Both allow you to pack up executable things and data together. OO does it by attaching methods to objects, while functional languages do it by using closures to capture data. Thus, if functional languages are self-modifying, Java is too. But Java is not normally thought of as a self-modifying language (except for reflection), and Java code is often verbose. (By the way, Guy Steele, one of the designers of Java, was also one of the people who designed the Lisp dialect Scheme--a more purely functional language than Common Lisp--in order to experiment with object-oriented programming! I believe that the idea was to construct different object-oriented language constructs using closures.)
Caveat: I haven't done any hard-core Java programming in a while, and there are probably language features relevant to this issue of which I'm unaware.

- 8,689
- 2
- 42
- 70
-
this is not the right answer but since stackoverflow watchdogs will prevent this from being answered, i will accept it as correct as a thank you for the attempt to answer. – necromancer May 03 '13 at 02:53
-
Thanks @agksmehx, and I apologize to the good people who voluntarily keep things running smoothly here. – Mars May 04 '13 at 03:46