Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 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
or
w3: to-path w3
select w3 'baz
Is not possible too
nedzadarek
@nedzadarek
@GiuseppeChillemi get doesn't allow path! and reduce doesn't work... I'll check alternatives.
^^ yes, not possible
@GiuseppeChillemi hmm.. this work:
>> ? :w
FOO/BAR/BAZ is an integer of value: 42
GiuseppeChillemi
@GiuseppeChillemi
It is possible to use the
w: 'FOO/('REDUCES-TO-BAR)/BAZ
? :w

@nedzadarek

w: 'FOO/(:REDUCES-TO-BAR)/BAZ

is the answer

(REBOL 2)
nedzadarek
@nedzadarek
@GiuseppeChillemi I found that reduce does not reduce path (I am not sure why) but it is happy with a block:
type? first [w]
; == word!
type? first reduce [w]
; == path!
 first reduce [w]
; == foo/bar/baz
first reduce reduce [w]
; == 42
GiuseppeChillemi
@GiuseppeChillemi

I have enough information...

But still have to understand why this works:

foo/('bar)/baz
nedzadarek
@nedzadarek
@GiuseppeChillemi do you mean paren! (()) and 'bar inside it?
GiuseppeChillemi
@GiuseppeChillemi
Yes
hexpected paren! () and :bar
*expected
nedzadarek
@nedzadarek
As parens in the paths are evaluated you will end up with the value that bar points to. What you want is word! (or any-word! - more later if you need additional informations*).
* it is all the same for red if you want select something:
>> arr: [a 42]
== [a 42]
>> select arr to-word "a"
== 42
>> select arr probe to-word "a"
a
== 42
>> select arr probe to-get-word "a"
:a
== 42
>> select arr probe to-set-word "a"
a:
== 42
>> select arr probe to-lit-word "a"
'a
== 42
GiuseppeChillemi
@GiuseppeChillemi
@nedzadarek
To me 'something mean "literal word", so no-translation
nedzadarek
@nedzadarek
@GiuseppeChillemi it is not that simple. At "top" level it says "do not evaluate this word", a: 'b. You will end up with a word!: ? a. In a block words/pathes are not evaluated so you will end up with lit-word! (type? first ['a]).
GiuseppeChillemi
@GiuseppeChillemi
Totally obscure at the moment
Needs more information
Needs input ! Beep !
nedzadarek
@nedzadarek
@GiuseppeChillemi What do you do not understand?
GiuseppeChillemi
@GiuseppeChillemi

@nedzadarek

@GiuseppeChillemi it is not that simple. At "top" level it says "do not evaluate this word", a: 'b. You will end up with a word!: ? a. In a block words/pathes are not evaluated so you will end up with lit-word! (type? first ['a]).

The whole explanation

Vladimir Vasilyev
@9214
@GiuseppeChillemi can you reformulate your question once again?
nedzadarek
@nedzadarek

@GiuseppeChillemi
When you set words to some values, <word>: <value> (e.g. the-answer: 42). <value> will be evaluated.

  • integer! (e.g. 42) will give you 42 (the value looks the same).
  • float! (e.g. 3.14) will give you 3.14
  • string!, pair! (2x14) and some more - like above

There are some "special" cases:

  • path! (e.g. foo/4) will be evaluated. For example you have foo: [1 2 3 4], when you set value to some word, val: foo/4, path foo/4 will be evaluated. foo/4 will be changed, in this case, to the 4th value of the foo (4).
  • lit-path! (e.g. 'foo/4) will be evaluated to path! foo/4. As you know already, you can get or reduce it. w: foo/4 and get w will give you 4 (4th element of the foo).
  • get-path! will get you value that it points to. It is like path!. However with path! you cannot get function!s for example (funs: #() funs/not-fibo: func [a] [ a - 10], funs/not-fibowill try to call not-fibo in the funs map, it will raise an error because you haven't provided an argument). You can get such value by using lit-path!: my-fun: :funs/not-fibo. After this you can call it like any other function: my-fun 12
  • block! every value within a block will be "the same", it won't use "special" rules that govern path!, lit-path! and get-path!. For example you have a block my-block: [42 3.14 "string" word :get-word 'lit-word set-word: [another block with a word]], you can see that *-path are not evaluated:
    Helper:

    foreach element my-block [
      print "Value: "
      probe element
    
      print "Type: "
      print mold type? element
    
      print "####"
      ]

    Output:

    Value: 
    42
    Type: 
    integer!
    ####
    Value: 
    3.14
    Type: 
    float!
    ####
    Value: 
    "string"
    Type: 
    string!
    ####
    Value: 
    word
    Type: 
    word!
    ####
    Value: 
    :get-word
    Type: 
    get-word!
    ####
    Value: 
    'lit-word
    Type: 
    lit-word!
    ####
    Value: 
    set-word:
    Type: 
    set-word!
    ####
    Value: 
    [another block with a word]
    Type: 
    block!
    ####

    And last value [another block with a word] will not evaluate words inside (you have no errors because there is no another and a word defined).

btw. tested on Red for Windows version 0.6.3 built 26-Mar-2018/1:14:22+02:00
Vladimir Vasilyev
@9214
@GiuseppeChillemi, @meijeru extensively documented evaluation rules here, if that's what you're interested in.
lepinekong
@lepinekong_twitter
Would it be easy to create a mathematical animation like this in red :)
https://i.imgur.com/IOJSlj0.jpg
https://www.youtube.com/watch?v=-X49VQgi86E
GiuseppeChillemi
@GiuseppeChillemi
@9214 , long day off work, I'll look at your exolaniotion this night or Tomorrow Morning
Giuseppe Chillemi
@GiuseppeChillemi_gitlab

@nedzadarek
Maybe yesterday we were after midnight but my question was different:
This is your code:

foo: [bar [baz 42]]
w: 'foo/bar/baz
get w
; == 42
reduce w
; == 42

I need something like:

z: bar
foo: [bar [baz 42]]
w: 'foo/(z)/baz
get w
; == 42
reduce w
; == 42

(I am just closing my day at work, I'll read it later)

Vladimir Vasilyev
@9214
@GiuseppeChillemi_gitlab perhaps you meant z: 'bar. Aside from that your example already works as you want.
Giuseppe Chillemi
@GiuseppeChillemi_gitlab
Yes ! z: 'bar
So if I write: z: 25, the whole path will be reduced to 'foo/25/'bar
Vladimir Vasilyev
@9214
>> append pick foo: append/only/dup [] [] 25 25 [bar yes]
== [bar yes]
>> z: 25
== 25
>> path: 'foo/(z)/bar
== foo/(z)/bar
>> reduce path
== yes
GiuseppeChillemi
@GiuseppeChillemi

@9214
I correct myself:
This does not work:

w: 'FOO/(:REDUCES-TO-BAR)/BAZ

This works:

first reduce reduce [w]
(Talking about REBOL2)
Chris Prinos
@cprinos

follow up to an earlier question on storing/manipulating functions in series...
with this code:

a: function [x] [x + 1]
b: function [x] [x * 2]
c: function [x] [x * x]

funcs:  reduce [:a :b :c]

foreach f funcs [ probe f 5]
foreach f funcs [ print f 5]
foreach f funcs [ print type? f 5]

I get different results via the interpreter red test.red vs compiled red -c -o test test.red

output with the interpreter:

6
10
25
6
10
25
integer
integer
integer

and with the compiled version:

func [x][x + 1]
func [x][x * 2]
func [x][x * x]
?function?
?function?
?function?
function
function
function

why the difference ?

Palaing
@Palaing
@rebolek Thank you! I thought cd was just an alias of change-dir
Boleslav Březovský
@rebolek
@Palaing You're welcome. It's almost alias. See that change-dir takes dir, but cd takes :dir, so it does not evaluate, OTOH you can do cd dir instead of cd %dir.
Vladimir Vasilyev
@9214
@cprinos difference stems from the fact that current compiler supports only a limited set of language, and cannot handle dynamic constructs such as in your example. Try to compile with -r -e flags instead.
lepinekong
@lepinekong_twitter
@Palaing I have developped cd which combines CD and @toomasv Tree here https://redlang.red/cd
and it works with variable and is tolerant with different file path format. So for example, you can try:
do https://redlang.red/cd
windows: c:\windows
cd windows
It works except it will print Tree twice a bug not a feature :)
dsunanda
@dsunanda
I am trying to create a PANEL with spacing of 0x0 - but the SPACE 0x0 seems to be ignored. In the code below, the red box has an OFFSET of 10x10. In R2 it would be 0x0. Any ideas, thanks?
unview/all
view/no-wait layout/tight [ 
    across space 0x0
    my-panel: panel [across space 0x0
          box 100x100 red  box 100x100 blue
          return
          box 100x100 pink box 100x100 green 
          ]
    ]
foreach box my-panel/pane [box/text: form box/offset show box]
do-events
Toomas Vooglaid
@toomasv
@dsunanda Add origin 0x0 to panel:
unview/all
view/no-wait layout/tight [ 
    across space 0x0
    my-panel: panel [origin 0x0 across space 0x0
          box 100x100 red  box 100x100 blue
          return
          box 100x100 pink box 100x100 green 
          ]
    ]
foreach box my-panel/pane [box/text: form box/offset show box]
do-events
dsunanda
@dsunanda
Perfect! Thanks!!
Max
@moliad

@lepinekong_twitter

@cprinos difference stems from the fact that current compiler supports only a limited set of language, and cannot handle dynamic constructs such as in your example. Try to compile with -r -e flags instead.

Is there some complete documentation about these differences? its a big deal for my project.

Vladimir Vasilyev
@9214
Not that I know of.
Max
@moliad
:sob:
Toomas Vooglaid
@toomasv
@dsunanda You are welcome!
Palaing
@Palaing
@lepinekong_twitter great! it does much more than I needed ;)
lepinekong
@lepinekong_twitter
@Palaing sure because I didn't do it for you but for me ;)