Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Oct 20 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
GiuseppeChillemi
@GiuseppeChillemi
Many things still to learn
REDBOL is a small giant universe.
dsunanda
@dsunanda
Lot's to learn - that makes it fun! You can fake up a cheap version of APPLY as below -- it won't handle /refinements:
apply: func [fun data /local blk][blk: copy [] append blk data insert blk 'fun do blk]
apply :foo bar  ;; as before
Vladimir Vasilyev
@9214
Or just
apply: func [function data][do compose [function (data)]]
>> apply: func [function data][do compose reduce [function quote (data)]]
== func [function data][do compose reduce [function quote (data)]]
>> apply 'reverse/part [[a b c d] 2]
== [b a c d]
Ungaretti
@Ungaretti
The predefined word what lists all predefined words of Red. Is there a way to list the words (variables) I created? In other words, to list Red's "dictionary"? Is calling that "dictionary" wrong?
Vladimir Vasilyev
@9214
@Ungaretti words-of system/words
Ungaretti
@Ungaretti
Boy you are fast!
Thanks.
Vladimir Vasilyev
@9214
@Ungaretti though, you'll need first to mark a "clean slate" point in this series. Even then you'll be able to track only words that have different spelling from the existing ones.
And it will track any words you've mentioned :wink:
>> skip tail words-of system/words -5
== [right-menu left-command right-command caps-lock num-lock]
>> 'abracadabra
== abracadabra
>> skip tail words-of system/words -5
== [left-command right-command caps-lock num-lock abracadabra]
>> [what? no this can't be serious!]
== [what? no this can't be serious!]
>> skip tail words-of system/words -5
== [what? this can't be serious!]
:point_up: note that no isn't among the last 5 "mentioned" words, because it was already pre-defined.
Vladimir Vasilyev
@9214
And, in general, you can't list all words you've created (by "created" I guess you mean setting word to some value in the form word: value), because they can be in local contexts / function's bodies.
I mean, you can, but that will require some grunt work.
Ungaretti
@Ungaretti
Interesting. I would like to understand how Red works internally, specially the (mechanism that looks like a) dictionary. Red stores the "links" between words and data. I can see how words are stored, but can't figure how it links them to, say, integers. This is not a question, don't bother explaining. Just wondering...
I guess I could list my variables with a combination of the code you posted plus get.
Vladimir Vasilyev
@9214

I would like to understand ... don't bother explaining

:confused:

Ungaretti
@Ungaretti
:smile: Just a wish for the future.
Vladimir Vasilyev
@9214
Red doesn't store links between words and data, it stores links between word and a "dictionary" where its value resides, and some additional info to fetch this value indirectly via link to a "dictionary".
Ungaretti
@Ungaretti
I want to save your time for my more important questions.
So there is something inside that may be called a "dictionary"! Good to know.
Vladimir Vasilyev
@9214
It's called a context.
Ungaretti
@Ungaretti
Isn't context a fancy word for object?
Vladimir Vasilyev
@9214
@Ungaretti nope. Objects provide a context, but they are not contexts themselves.
Functions, when you call them, provide contexts too.
Ungaretti
@Ungaretti
I got it wrong then. Have to check my notes. But isn't make object!,context and object pretty much the same?
I mean, as commands?
Vladimir Vasilyev
@9214

@Ungaretti context is a wrapper around make object!:

>> source context
context: func ["Makes a new object from an evaluated spec" 
    spec [block!]
][
    make object! spec
]

object is a... well, see yourself :wink:

Ungaretti
@Ungaretti
@9214 Thanks once more!
Wait, it says there object: :context, so they are the same?
Vladimir Vasilyev
@9214
>> same? :object :context
== true
Ungaretti
@Ungaretti
Aha!
And doesn't make object! creates and object in the same way as object? So context would be a wrapper around object
Vladimir Vasilyev
@9214
@Ungaretti well, yes, they are all aliases.
Ungaretti
@Ungaretti
:thumbsup:
BeardPower
@BeardPower
Not so much of a wrapper, but they are different.
Red/System:

Namespaces are not objects!

Even if they look like objects, namespaces only exist at compilation time, so they cannot be manipulated at run-time.

context is a namespace.
Vladimir Vasilyev
@9214
@BeardPower cool. Now you have to explain what a namespace is :wink:
BeardPower
@BeardPower
@9214 A namespace provides local contexts able to encapsulate source code.
In computing, a namespace is a set of symbols that are used to organize objects of various kinds, so that these objects may be referred to by name.
Namespaces are commonly structured as hierarchies to allow reuse of names in different contexts.
Vladimir Vasilyev
@9214

Namespaces are commonly structured as hierarchies

Except that there's no hierarchy between contexts whatsoever.

BeardPower
@BeardPower
:older_man: :bulb:
nedzadarek
@nedzadarek
@BeardPower but using the interpreter I can manipulate contexts. It is good to know such differences between compilation and interpretation.
Vladimir Vasilyev
@9214
@nedzadarek you can't manipulate contexts, only functions and objects.
Context is an internal runtime datatype, not accessible to a user.