Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Oct 20 2019 22:59
    @dockimbel banned @SmackMacDougal
  • Dec 03 2017 05:53
    @PeterWAWood banned @matrixbot
  • Sep 28 2016 12:19
    @PeterWAWood banned @TimeSeriesLord
  • Aug 13 2016 03:23
    @PeterWAWood banned @Vexercizer
Vladimir Vasilyev
@9214
I'd rather wrap myself in a blanket now.
hiiamboris
@hiiamboris
;)
nedzadarek
@nedzadarek

@9214

you apply function to one argument and it returns you

Well... I need some sleep

hiiamboris
@hiiamboris
to clarify the point above:
spec(x0,f(x,y,z)) when called returns spec(y0,f(y,z,x=x0)), and the new one => f(z,x=x0,y=y0)
so you only have to call spec() once on a normal function to construct a currying variant, and then each call just adds an argument until there's only one argument remains and the function itself is returned
it's all great in theory though, but in practice a returned function will be just data (it won't accept arguments yet), so you'll need an operator (or do reduce [..]) to call it
hiiamboris
@hiiamboris
@9214 as a master bindologist, might you have any insight on the following performance data?
x: 1
....
0:00:00.442000001 [get in context? 'x 'x]
0:00:00.238000001 [get bind 'x context? 'x]
Gregg Irwin
@greggirwin
@hiiamboris, bind and in do their work differently, as you can see in the R/S code. We'd have to profile the internals to see what's slower, aside from obvious overhead of extra func calls between find-word/bind-word. Doc might say, but he's busy.
Nenad Rakocevic
@dockimbel
@hiiamboris in requires a stack slot copy while bind just modifies the first argument slot on stack, and re-use it as returned value. The incurred overhead exists because such copy boils down to an expensive memcpy(), which could be replaced in a future (once we start working on optimizations) by a simple read/write using an SSE 128-bit wide register. Once such optimization is done, the difference should become insignificant.
hiiamboris
@hiiamboris
hmm.. interesting, thank you @dockimbel !
Vladimir Vasilyev
@9214
Guh, I'm late :(
@hiiamboris my answer would the basic version of @dockimbel's - bind modifies context pointer in slot and returns it, while in allocates an extra copy, so as to avoid modification of the original word (I guess?).
lepinekong
@lepinekong_twitter
@toomasv I can't find composite in help ?
Toomas Vooglaid
@toomasv
@lepinekong_twitter :point_up: April 6, 2018 1:14 AM
lepinekong
@lepinekong_twitter
I feel frustrated: why this basic switch doesn't work :smile:
type: word!; 

probe type? type ; datatype!
probe type? word! ; datatype!
probe (type = word!); true

switch type [

    unset! [
        print "unset!"
    ] 
    word! string! file! url! block! [
        print "word! string! file! url! block!"
    ]
]
Vladimir Vasilyev
@9214
@lepinekong_twitter switch type?/word
lepinekong
@lepinekong_twitter
@toomasv ah ok thanks I didn't remember
@9214 that's my point why would I need type?/word since type? type and type? word! are same so that (type = word!)
Vladimir Vasilyev
@9214
>> switch 'word! [word! [print "word!"]]
word!
@lepinekong_twitter you're switching by datatype, but your block contains words.
lepinekong
@lepinekong_twitter
value [any-type!] "The value to match".
Vladimir Vasilyev
@9214
>> block: [word! [print "word!"]]
== [word! [print "word!"]]
>> type? word!
== datatype!
>> type? block/1
== word!
>> type? type? block/1
== datatype!
>> type? type?/word block/1
== word!
lepinekong
@lepinekong_twitter
@9214 so inside block it becomes word ? but why value is of type any-type! instead of word!
Vladimir Vasilyev
@9214
@lepinekong_twitter what..?
What any-type! has to do with that?
lepinekong
@lepinekong_twitter
according to help
Vladimir Vasilyev
@9214
every value is any-type!
lepinekong
@lepinekong_twitter
so why can't I test datatype!
Vladimir Vasilyev
@9214
What you have inside block are words, not datatypes
but you're switching by datatype
BeardPower
@BeardPower
@9214 word
Vladimir Vasilyev
@9214
You can use construction syntax instead, that way block will contain a datatype, not a word that looks like datatype:
>> switch 'word! [word! [print "word!"]]
word!
>> switch word! [#[word!] [print "word!"]]
word!
Toomas Vooglaid
@toomasv
@lepinekong_twitter
Tortured
switch type compose [(word!) [print "word!"]]
== word!
lepinekong
@lepinekong_twitter
@9214 ah ok thanks I like 'word! better
Vladimir Vasilyev
@9214
lepinekong
@lepinekong_twitter
@toomasv too much :smile:
BeardPower
@BeardPower
@9214 That's RDM for the new century :)
Vladimir Vasilyev
@9214
>> word? 'bird!
== true
BeardPower
@BeardPower
I expect some new interpretation from you soon: The Red is a lang! :)
nedzadarek
@nedzadarek
Can we make a wiki that contains links to parse's stuffs?
and they are already covered here, so I don't see a need in another collection of links
nedzadarek
@nedzadarek
@9214 but are there some difference between Red's and Rebol 2 & Rebol 3 's parse?
ps. that I cannot think because I sing the song!
Vladimir Vasilyev
@9214
@nedzadarek Red's parse is more sophisticated than R2 version, but on a par with R3, I guess.
nedzadarek
@nedzadarek
Then I would like to keep such informations... if possible.
Vladimir Vasilyev
@9214
@nedzadarek you don't need to ask for permission to start a wiki page, if that's what you mean.
nedzadarek
@nedzadarek
That's good to know! Thank you.
Gregg Irwin
@greggirwin

@lepinekong_twitter, at this stage in your Red career, if someone offers a hint, clue, or suggestion in answer to a question or problem you pose, please take some time to understand their response, rather than immediately saying "Why would I need to...?"

Do you understand the behavior now? If not, does this help?

type: word!
blk: [
    unset! [
        print "unset!"
    ] 
    word! string! file! url! block! [
        print "word! string! file! url! block!"
    ]
]
switch type blk

find blk type

type? type
find blk type? type

type? first blk
find blk 'word!

switch type reduce blk

There should be no more explanation needed than this, and is an example of how to go about learning and debugging on your own.

Before pasting the entire thing into a console, see if you can predict what each result will be, then add the next statement. If the result isn't what you expected, think about it and see if the result makes sense.