Emeka, I noticed that I introduced some errors into the console session that I copied below, so I have removed those errors because I am afraid that I may confuse you. I.E. disregard my previou email and concentrate on this one. cheers tim * Emeka <[email protected]> [100910 02:43]: > Tim, > > Thanks so much! > > If you won't mind could you throw more light on this: > "Also, I recommend that you familiarize yourself with > the rebol function interface dialect." > > > I would like to see examples. Here's a start: Go to http://www.rebol.com/rebolsteps.html Do a search on "dialect" You should see the following statement: """ You have already seen some simple dialects. For instance, the list of arguments to a function is a dialect that can contain many variations other than those which have been shown here """ Now go here: http://www.rebol.com/docs/core23/rebolcore-9.html Look for the link Titled: "3.1 Interface Specifications" To further edify yourself, write some functions for yourself Example: >> test: func[a[integer! decimal!]][?? a] >> test 1 a: 1 == 1 >> test 2.3 a: 2.3 == 2.3 >> test "abc" ** Script Error: test expected a argument of type: integer decimal ** Near: test "abc" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Now here is the tricky part, but *I* think that it is *very* important that you understand this part ================================================================= In rebol a subroutine: of which there are several *and* you can "roll your own" - are not compiled into the rebol binary but are themselves written in rebol. Your can do the follow right from the rebol command line ================================================================= >> source function function: func [ "Defines a user function with local words." spec [block!] {Optional help info followed by arg words (and optional type and string)} vars [block!] "List of words that are local to the function" body [block!] "The body block of the function" ][ make function! head insert insert tail copy spec /local vars body ] >> source func func: func [ "Defines a user function with given spec and body." [catch] spec [block!] {Help string (opt) followed by arg words (and opt type and string)} body [block!] "The body block of the function" ][ throw-on-error [make function! spec body] ] >> source has has: func [ {A shortcut to define a function that has local variables but no arguments.} locals [block!] body [block!] ][function [] locals body] >> source does does: func [ {A shortcut to define a function that has no arguments or locals.} [catch] body [block!] "The body block of the function" ][ throw-on-error [make function! [] body] ] >> ================================================================= In fact, I have written my own rebol subroutine call 'def, which like a python def construct, automatically generates local variables, and I just about always use 'def for global subroutines. HTH regards tim
> > Regards, > Emeka > > On Thu, Sep 9, 2010 at 8:28 PM, Tim Johnson <[email protected]> wrote: > > > > > * Emeka <[email protected]> [100909 09:59]: > > > Hello All, > > > > > > I have the below solution, but I want something better. > > > > > > > > > Ismember?: func[my-list start-n n t-element][ > > > first-element: first at my-list start-n > > > if t-element = first-element [return true] > > > if start-n = n [return false] > > > Ismember? my-list ADD start-n 1 n t-element > > > ] > > The last line: > > > Ismember? my-list ADD start-n 1 n t-element > > > > would be better coded: > > Ismember? my-list (ADD start-n 1) n t-element > > for readability, precedence and disclosure of intent. > > > > Also, I recommend that you familiarize yourself with > > the rebol function interface dialect. > > > > IOWS, you can control the data sent to the function > > by specifying the datatypes of the arguments > > > > Example: > > Ismember?: func[my-list[block!] start-n[integer!] n[integer!] > > t-element[any-type!]][ > > ;; .... code here > > ] > > This approach has at least two advantages: > > 1)Clarifies the intent of the function > > 2)Generates error messages at the function call rather than > > somewhere down the road where some side effect kicks in as > > a result of an unintended argument type. > > > > I hope this helps. If I have confused the issue more, :) I can > > elaborate. > > tim > > > > > On Thu, Sep 9, 2010 at 6:38 PM, Emeka <[email protected]> wrote: > > > > > > > > > > > Hello All, > > > > > > > > Which word would I use for something like this? I have a block [ A B C > > D] , > > > > I would like to do > > > > Ismember? [A B C D] D comes true because D is in the block already , > > but > > > > Ismember?{A B C D] F comes false. > > > > > > > > > > > > Regards, > > > > Emeka > > > > > > > > -- > > > > *Satajanus Nig. Ltd > > > > > > > > > > > > * > > > > > > > > > > > > > > > > -- > > > *Satajanus Nig. Ltd > > > > > > > > > * > > > > > > > > > -- > > > To unsubscribe from the list, just send an email to > > > lists at rebol.com with unsubscribe as the subject. > > > > > > > -- > > Tim > > tim at johnsons-web.com or akwebsoft.com > > http://www.akwebsoft.com > > -- > > To unsubscribe from the list, just send an email to > > lists at rebol.com with unsubscribe as the subject. > > > > > > > -- > *Satajanus Nig. Ltd > > > * > > > -- > To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject. > -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com -- To unsubscribe from the list, just send an email to lists at rebol.com with unsubscribe as the subject.
