Help
[1/8] from: emekamicro:g:mail at: 9-Sep-2010 18:38
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
*
[2/8] from: henrikmk:g:mail at: 9-Sep-2010 19:46
On Thu, Sep 9, 2010 at 7:38 PM, Emeka <emekamicro-gmail.com> 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 , =A0but
> Ismember?{A B C D] F comes false.
Simply use FIND:
find [a b c d] 'd
== [d]
FIND returns the block at the index of the found item. If not found,
it returns NONE.
This is nice and simple, because it interacts directly with IF or EITHER:
either find [a b c d] 'd [
print "member found"
][
print "member not found"
]
Depending on the content of the block, you may need to use FIND/ONLY
If you really want logic! output, you can add a FOUND?:
found? find [a b c d] 'd
== true
--
Regards,
Henrik Mikael Kristensen
[3/8] from: emekamicro:gma:il at: 9-Sep-2010 18:48
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
]
On Thu, Sep 9, 2010 at 6:38 PM, Emeka <emekamicro-gmail.com> wrote:
> Hello All,
> Which word would I use for something like this? I have a block [ A B C D] ,
<<quoted lines omitted: 6>>
> *Satajanus Nig. Ltd
> *
--
*Satajanus Nig. Ltd
*
[4/8] from: tim-johnsons:web at: 9-Sep-2010 11:28
* Emeka <emekamicro-gmail.com> [100909 09:59]:
> Hello All,
> I have the below solution, but I want something better.
<<quoted lines omitted: 4>>
> 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 <emekamicro-gmail.com> wrote:
> >
<<quoted lines omitted: 21>>
> 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
[5/8] from: emekamicro:gm:ail at: 10-Sep-2010 11:36
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.
Regards,
Emeka
On Thu, Sep 9, 2010 at 8:28 PM, Tim Johnson <tim-johnsons-web.com> wrote:
> * Emeka <emekamicro-gmail.com> [100909 09:59]:
> > Hello All,
<<quoted lines omitted: 73>>
> To unsubscribe from the list, just send an email to
> lists at rebol.com with unsubscribe as the subject.
--
*Satajanus Nig. Ltd
*
[6/8] from: tim-johnsons:web at: 12-Sep-2010 17:43
* Emeka <emekamicro-gmail.com> [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: function[a[integer! decimal!]][?? a]
** Script Error: function expected body argument of type: block
** Near: test: function [a [integer! decimal!]] [?? a]
>> test: function[][]
** Script Error: function expected body argument of type: block
** Near: test: function [] []
>> x: function[][]
** Script Error: function expected body argument of type: block
** Near: x: function [] []
>> 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
<<quoted lines omitted: 92>>
> 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
[7/8] from: tim-johnsons:web at: 13-Sep-2010 11:06
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 <emekamicro-gmail.com> [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
<<quoted lines omitted: 92>>
> 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
[8/8] from: emekamicro::gmail at: 13-Sep-2010 20:28
Tim,
Thanks so much!
Regards,
Emeka
On Mon, Sep 13, 2010 at 8:06 PM, Tim Johnson <tim-johnsons-web.com> wrote:
> Emeka, I noticed that I introduced some errors into the
> console session that I copied below, so I have removed
<<quoted lines omitted: 207>>
> To unsubscribe from the list, just send an email to
> lists at rebol.com with unsubscribe as the subject.
--
*Satajanus Nig. Ltd
*
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted