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 believe we have a ticket about it, lemme check...
hiiamboris
@hiiamboris
probably a closed ticket anyway
Vladimir Vasilyev
@9214
Yup red/red#2876
Nenad Rakocevic
@dockimbel
@9214 I don't think that a "definitional return" is an adequate solution, as it's too limitating. You can easily build code dynamically from pieces coming out of the function's body. The Rebol2 way seems more flexible. Though, as it's a minor feature, I haven't given it much thoughts for now. It's in the todo-list of language features to process once we get all the big pieces implemented.
Vladimir Vasilyev
@9214
@dockimbel I once stumbled on a case where block with return passed to one function from another actually returned from the function where it was defined, or something like that.
Nenad Rakocevic
@dockimbel
@9214 In R2? I vaguely remember some cases like that, but were the function attributes used? Such cases are rare enough anyway.
Vladimir Vasilyev
@9214
Haven't checked it, but now I think that re-binding this block to function's context should've fixed it.
@dockimbel no, in Red. I don't really remember exact details, it was only once, somewhere in September.
hiiamboris
@hiiamboris
@9214 nice idea! reduce f: func [] [ do reduce does [return [probe "HAI" return 100]] ] does the trick of returning stuff from f
let's redefine return!
Nenad Rakocevic
@dockimbel
@hiiamboris Here is a way to make it work the way you want using a custom function constructor :
loop-thru: function [cond body] [
    return: does [throw/name () 'return]
    while cond bind body 'body
]

func2: func [spec [block!] body [block!]][
    func spec compose/only [catch/name (body) 'return]
]

f: func2 [x] [
    loop-thru [x < 10] [x: x + 1 if x = 5 [return]]
    print "you see where return takes me?"
]

f 2
@hiiamboris reduce <function> has no effect. You can remove all those reduce you are using.
Vladimir Vasilyev
@9214
so as do reduce
hiiamboris
@hiiamboris
have you both tried it?
Nenad Rakocevic
@dockimbel
@hiiamboris
>> reduce does [return [probe "HAI" return 100]]
== func [][return [probe "HAI" return 100]]
>> does [return [probe "HAI" return 100]]
== func [][return [probe "HAI" return 100]]
hiiamboris
@hiiamboris
>> reduce does [print "HAI"]
HAI
nedzadarek
@nedzadarek
@hiiamboris no... oh stable... not in newer builds
hiiamboris
@hiiamboris
okay, it's in the stable only, again, not in newer builds
how do I construct-and-run a function then?
Vladimir Vasilyev
@9214
@hiiamboris
== lambda: func [spec body args][do reduce append [func spec body] args]
>> lambda [x][x + 1][1336]
== 1337
Nenad Rakocevic
@dockimbel
@hiiamboris You use do.
hiiamboris
@hiiamboris
>> do does [print "HAI"]
== func [][print "HAI"]
Vladimir Vasilyev
@9214
do reduce [func [...][...] x y z]
hiiamboris
@hiiamboris
right! great!
Nenad Rakocevic
@dockimbel
@hiiamboris Ah possible, yes, as we try to get rid of variable arity use-cases. Good that even do is not allowed anymore.
apply will be a better alternative once it gets implemented.
Vladimir Vasilyev
@9214
@rebolek :exclamation:
and alert sound from MGS :D
Boleslav Březovský
@rebolek
@9214 it's just toy implementation, Nenad has certainly something much better in mind.
nedzadarek
@nedzadarek
@hiiamboris maybe you can be more verbose and do something like this: f: func [args /local fun] [ fun: func [...][...] fun args]?
Nenad Rakocevic
@dockimbel
@9214 @rebolek You mean for apply?
Vladimir Vasilyev
@9214
Yes, @rebolek cooked up his version not so long ago.
hiiamboris
@hiiamboris
@nedzadarek looks... too verbose to my taste (:
nedzadarek
@nedzadarek
ok :|
Nenad Rakocevic
@dockimbel
Where can I see it? I have started working on one a while ago, but postponed it when I realised that it will take quite some time to support properly.
Boleslav Březovský
@rebolek
@dockimbel there's an article about it, but I'm on phone now, so can't post a link, sorry
Vladimir Vasilyev
@9214
Boleslav Březovský
@rebolek
@9214 can you help, please?
Vladimir Vasilyev
@9214
sure
Nenad Rakocevic
@dockimbel
@9214 That apply implementation works, but it's slow (calls Parse) and requires at least 3 series allocations, while it should consume no memory at all (just stack slots). That's why I went for a native implementation in R/S, which is quite complex actually to get right.
nedzadarek
@nedzadarek
load mold red-code should always work if red-code is a proper Red code, right?
Vladimir Vasilyev
@9214
@nedzadarek I'm not sure, there's mold/all but it's TBD.
Nenad Rakocevic
@dockimbel
@nedzadarek That statement would need mold/all to be true. Actually, even that won't be enough, as definitional bindings would not be preserved. Only mold/bin would really work (can store bindings too) once a Redbin encoder will be implemented in R/S (we only have a decoder for now).
Boleslav Březovský
@rebolek
@dockimbel as I said, it's toy implementation, showing what is possible, not something that should be included in Red. What I like about it though, is much easier syntax than in Rebol.
If you look at this and other articles, you may find that I'm trying to show how to implement new language features with as simple code as possible (of course limited by my mediocre abilities) to show that it's really not that hard. I'm not optimizing for speed/memory, but for readability.
Vladimir Vasilyev
@9214

mediocre abilities

this guy just asks for a tip :)

Boleslav Březovský
@rebolek
no, I'm just realist
Abdullah Yiğiterol
@abdllhygt
hi! : (
Vladimir Vasilyev
@9214
hi @abdllhygt, what's up?