-3

This code works:

  o: context [
    a: 1
  ]

  o/a

This one doesn't:

  o: context [
    a: 1
    return a
  ]
  o
  o/a

* Script Error: path o/a is not valid for integer! type * Where: catch *** Stack:

Is there a way to make the second one work ?

user310291
  • 36,946
  • 82
  • 271
  • 487

1 Answers1

4

return will force its function to return whatever value is provided. The thing is that context is a function too! So, when you do:

o: context [
    a: 1
    return a
]

o word will be set to a returned value from a context function, which takes a block, evaluates it according to make object! ... semantics (see details here), and returns a 1 integer in the process, because that's what you've asked it to do.

I'm not quite sure what else you've expected in this case. If you want o set o to an actual object! -- just don't use return.

9214
  • 2,105
  • 11
  • 15
  • I wanted O to return AND be able to call any O methods. – user310291 Sep 28 '18 at 12:16
  • 1
    i.e. you want `o` to be an integer AND an object at the same time..? – 9214 Sep 29 '18 at 03:34
  • Or do you want to set `o` to an object, but return a value of its `a` field as a result of the whole expression? `get in o: object [a: 1] 'a` ? – 9214 Sep 29 '18 at 03:40
  • O is an Object, I want to access a child implicitely: MSAccess VBA allowed this without requiring explicitely to name the default child. – user310291 Sep 29 '18 at 09:55