Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: MySQL protocol bug

From: joel:neely:fedex at: 19-Feb-2004 13:32

Hi, again, Maxim, Maxim Olivier-Adlhoch wrote:
> Which is why we can easily define and create nameless functions > on the fly (in other languages too) but how natural is it in > other languages. not very. >
> I'd like people with experience in scheme or ruby to butt in! > I'd like to see how rebol stands out compared to them. >
To quote from _The_Scheme_Programming_Language_, Third Edition by R. Kent Dybvig (2003, MIT Press): The general form of a lambda expression is (lambda (var ...) exp1 exp2 ...) The variables var ... are the formal parameters of the procedure, and the sequence of expressions exp1 exp2 ... is its body. ... A procedure is just as much an object as a number, string, symbol, or pair. with almost complete parallelism to REBOL's 'func behavior. WRT Ruby, a "block" can be thought of as an anonymous function. An example from _Programming_Ruby_-_The_Pragmatic_Programmer's_Guide_ by Dave Thomas and Andy Hunt (2001, Addison Wesley Longman, Inc.) illustrates the syntax. The expression @songs.find { |aSong| key == } supplies a block with one parameter to the "find" method of Array. (The variable "key" is from the immediately-surrounding context.) The nearest REBOL equivalent for that line I can think up quickly would use an equivalent to Ruby's built-in "find": find-if: func [s [series!] f [any-function!]] [ foreach item s [ if f item [return item] ] ] If SONGS is a block of blocks [ [name artist duration] ... ] such as [["Proud Mary" "CCR" 4:30] ["Silk Road Suite" "Kitaro" 65:25] ...] and then express the above Ruby code with something resembling find-if songs func [aSong] [key = aSong/1] so (after we define all the supporting machinery) there's not a great deal of difference in typing effort.
>> >> > without choking... not even python will let you insert a >> > string anywhere in its code, if its not being used by a >> > function. > > should have read: "not even python will let you insert a > VALUE OF RANDOM TYPE anywhere in its code" > > just tested with an integer and python chokes. >
I just tested with an integer and Python wasn't bothered at all:
>>> def somefunc (x, y):
... """another, even sillier function""" ... x2 = x * x; ... y2 = y * y; ... 13; ... print x2 + y2; ...
>>> somefunc (3, 4)
25 Note the gratuitious insertion of 13...
> I wish rebol could at least tell you in which SCRIPT FILE > a crash occurs! >
I must admit I still don't know what that means. Consider the following case: File a.r contains wordlist: [a b d] File b.r contains exprlist: [a + b / c] File c.r contains container: reduce [ func replace/all wordlist 'd 'c replace/all exprlist 'd 'c ] File d.r contains test: func [x] [container/1 1 3 x] and the user types test 0 which, when evaluated, produces ** Math Error: Attempt to divide by zero ** Where: 1 ** Near: a + b / c Now, I really don't know how to answer the question "Which script file did the error occur in?" Can you enlighten me? -jn- -- Joel Neely com dot fedex at neely dot joel I had proved the hypothesis with a lovely Gedankenexperiment, but my brain was too small to contain it. -- Language Hat