Giter Site home page Giter Site logo

value? fails about red HOT 8 CLOSED

TimeSeriesLord avatar TimeSeriesLord commented on July 22, 2024
value? fails

from red.

Comments (8)

greggirwin avatar greggirwin commented on July 22, 2024

value? is fine, and correctly throwing an error. You need to pass a word! to it, where the errors clearly tell you that you aren't. Try n: 23 value? 'n. You need to understand evaluation. Just as important, please use Gitter to ask if things are bugs, after you've seen if there's already a ticket for them, before opening tickets.

from red.

TimeSeriesLord avatar TimeSeriesLord commented on July 22, 2024

So this is Reddish behavior? It differs from REBOL 2.7.8 and Rebol 3

REBOL 2.7.8

 >> value? 12
== true
>> value? #{0A6B14728C4DBEF5} 
== true

Rebol 3

>> value? 12
== true

>> value? #{0A6B14728C4DBEF5} 
== true


But in Red 0.6.5

>> value? 12
*** Script Error: value? does not allow integer! for its value argument
*** Where: value?
*** Near : value? 12
*** Stack:  

>> type? #{0A6B14728C4DBEF5} 
== binary!
>> value? #{0A6B14728C4DBEF5} 
*** Script Error: value? does not allow binary! for its value argument
*** Where: value?
*** Near : value? #{0A6B14728C4DBEF5}
*** Stack:  

Isn't value? 'n merely asking the interpreter if a literal value is an irreducible value, i.e., a symbol of itself?

from red.

TimeSeriesLord avatar TimeSeriesLord commented on July 22, 2024

Your answer seems to be wrong, unless it a design decision for Red. Here is why:

>> value? 'zzz
== true
>> ?? zzz
zzz: unset!
>> get zzz
*** Script Error: zzz has no value
*** Where: get
*** Near : get zzz
*** Stack:  

from red.

qtxie avatar qtxie commented on July 22, 2024

@TimeSeriesLord Seems you are using an old version of Red.

>> value? 'zzz
== false
>> ?? zzz
zzz: unset!
>> about
Red 0.6.5 for Windows built 6-Apr-2024/8:45:40+08:00  commit #36adc61

from red.

greggirwin avatar greggirwin commented on July 22, 2024

@TimeSeriesLord noted that it was a recent build in their first message. Hmmm.

from red.

greggirwin avatar greggirwin commented on July 22, 2024

Isn't value? 'n merely asking the interpreter if a literal value is an irreducible value, i.e., a symbol of itself?

No, because value? uses a "normal" argument, so when you call it, the argument is evaluated and value? only takes word! values. So you need to pass a lit-word! or value? first [...] to pass the word itself. Then value? can see if that word is set.
This is by design because everything in Redbol langs is a value so that's sort of meaningless. The doc string also makes it clear that we're talking about what a word refers to. It's still a little confusing and should be improved when we do the red specs project to clearly define more details. That is, everything is a value, but unset! is special in that it's sort of a non-value that exists largely for implementation reasons. The confusing part is that unset! is truthy (only false and none are falsy).

I thought it was discussed, but can't find it now, to use set? instead of value? as the name, and deprecate the former. That would make it much clearer.

e.g. in R2 you get this, because none! is a value, even though the doc string said "Returns TRUE if the word has been set.".

>> value? pick [] 1
== true

Which makes no sense.

from red.

TimeSeriesLord avatar TimeSeriesLord commented on July 22, 2024

Well thanks, Gregg! So in Red, value? functions differently than in REBOL 2.7.8 or Rebol 3.

In the latter two, value? sort of meant "has value" or "reducible to value".

In Red 0.6.5, it means "only if a word is set to another word, which might or might not be set to a value of some kind, e.g., an irreducible value, a function."

from red.

greggirwin avatar greggirwin commented on July 22, 2024

Not set to another word, but referring to anything other than unset. Here is the actual source code: https://github.com/red/red/blob/master/runtime/natives.reds#L2022

In Red it works roughly like this

set?: func [val [word!]][not unset? get/any :val]

Now, if we add some debug logic, it should be even more clear.

set?: func [
    val [word!]
][
    print [mold type? :val  :val  mold type? get/any :val]
    not unset? get/any :val
]

And some examples:

>> set? 'xxx
word! xxx unset!
== false
>> set? 'pi
word! pi float!
== true
>> my-word: 'xxx
== xxx
>> set? 'my-word
word! my-word word!
== true
>> set? my-word
word! xxx unset!
== false

from red.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.