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
Christian Ensel
@gurzgri
@GiuseppeChillemi Given selfwould be available in functions to access a function's context, self would no longer be available to access the context of a function's outer (object) context. Which is an ubiquitous pattern with OOP, and no doubt used in large codebases.
JLCyclo
@JLCyclo
yep! About github and repository red/community... I would like to add a script in the repository, but I can't make the pull request.. I click "create pull request" on github but nothing appears...
I made a fork: cyclo07/community and I woul like to create a pull request for red/community
GiuseppeChillemi
@GiuseppeChillemi

@gurzgri

@GiuseppeChillemi Given selfwould be available in functions to access a function's context, self would no longer be available to access the context of a function's outer (object) context. Which is an ubiquitous pattern with OOP, and no doubt used in large codebases.

I have read the article. In my scenario, a function is like an encapsulating object for words and functions but it has no way to access extend itself using SELF. It is somehow more limited than an object. While the encapsulator object method to have local variables and access them from the inner function solves thing, it forces to use a OBJECT-NAME/FUNCTION-NAME notation where FUNCTION-NAME is shorter and more readable.

GiuseppeChillemi
@GiuseppeChillemi
@gurzgri
I can see why function SELF could override SELF of the encapsulator object. Also like a newbye I could suggest having SELF with parents to navigate SELVES backwards if possible but I imagine is not so easy. Regarding this topic I have read there is no backlink in blocks and @9214 once "suggested" to read the code and try to write a double linked table (or something like this). Maybe it is the same reason why we have not nested SELVES which are backward accesible.
nedzadarek
@nedzadarek

@GiuseppeChillemi about "unnecessary" lines:
You can always edit it in the browser. Choice is yours.

About local words:
There are probably many ways to simulate it. You can keep local words in a map (1) or bind body words to some context (2).
1) f: function [/local local-words] [local-words: #() local-words/should-be-local: 42]
2) g: function [] bind [should-be-local] context [should-be-local: 42]

GiuseppeChillemi
@GiuseppeChillemi
@nedzadarek What you mean for "you can always edit in the browser" ?
About solution number 2: I do not understand it ;-)
Semseddin Moldibi
@endo64
@JLCyclo You should click on the Pull request link on your own fork: https://github.com/JLCyclo/community
Here you can see:
image.png
nedzadarek
@nedzadarek

When you paste your code into gitter ("Click here to type chat message...") you can delete/remove (or add) some characters.
For example this:

>> 7 * 6
== 42

I will change to this:

7 * 6
; == 42

(no >> and added comment - ;)

@GiuseppeChillemi

About solution number 2: I do not understand it ;-)

You know what binding is?

nedzadarek
@nedzadarek
ps. It might not work with recursive functions.
Greg T
@gltewalt
What is this strangeness about?
>> n: now
== 23-Feb-2019/23:48:26-07:00

>> repeat i 15 [print ["picking" i "from n returns:" pick n i]]
picking 1 from n returns: 23-Feb-2019
picking 2 from n returns: 2019
picking 3 from n returns: 2
picking 4 from n returns: 23
picking 5 from n returns: -7:00:00
picking 6 from n returns: 23:48:26
picking 7 from n returns: 23
picking 8 from n returns: 48
picking 9 from n returns: 26.0
picking 10 from n returns: 6
picking 11 from n returns: 54
picking 12 from n returns: -7:00:00
picking 13 from n returns: 8
picking 14 from n returns: 8
*** Script Error: value out of range: 15
*** Where: pick
*** Stack:
And with time!
>> pick 12:23 1
== 12
>> pick 12:23 2
== 23
>> pick 12:23 3
== 0.0
>> pick 12:23 4
*** Script Error: value out of range: 4
*** Where: pick
*** Stack:
Greg T
@gltewalt
Something I don't understand at the moment, or bugs?
Boleslav Březovský
@rebolek
see system/catalog/accessors
nedzadarek
@nedzadarek
@gltewalt I think time! is fine -> 1st, 2nd and 3rd values are hour, minutes and seconds with milliseconds (in float).
Toomas Vooglaid
@toomasv
@gltewalt Not bug. There are 15 accessors but 14 fields. 15 is not defined in date.reds:
>> pick system/catalog/accessors/date! 15
== julian
>> n/julian
== 55
>> n/15
*** Script Error: cannot access 15 in path n/15
And here's why there are 14 fields only:
sym = words/yearday     [field: 11]
sym = words/julian [field: 11]
hiiamboris
@hiiamboris
@toomasv but this (2 symbols mapped to one field) is a bug
Toomas Vooglaid
@toomasv
@hiiamboris Isn't it just an alias?
hiiamboris
@hiiamboris

That's what I just read on google:

The Julian day or Julian day number (JDN) is the number of days that have passed since the initial epoch defined as noon Universal Time (UT) Monday, January 1, 4713 BC in the Julian calendar

Toomas Vooglaid
@toomasv
Oh, then it is not yet implemented.
GiuseppeChillemi
@GiuseppeChillemi

@nedzadarek

@GiuseppeChillemi

About solution number 2: I do not understand it ;-)

You know what binding is?

I am learning it..

GiuseppeChillemi
@GiuseppeChillemi

@nedzadarek

Here:

2) g: function [] bind [should-be-local] context [should-be-local: 42]

g: function []

Your are defining the first part of the function

 bind [should-be-local]

Here I don't understand why [should-be-local] instead of 'should-be-local

 context [should-be-local: 42]

Here you create and object which is the body of the function.

I am missing the connection between the head of the function and its body with bind.

Greg T
@gltewalt
Got it
nedzadarek
@nedzadarek

@GiuseppeChillemi

Here I don't understand why [should-be-local] instead of 'should-be-local

Because I want to create a block not just a word (block? (bind [a] context[]) ; == true). function takes 2 arguments: 2 blocks (spec and body).

spec: [] 
body: [] 
function spec body

Let me group function's arguments using parens: function ( [] ) (bind [should-be-local] context [should-be-local: 42])
function's body is an empty block ([]) and body is bind [should-be-local] context [should-be-local: 42]
bind BLOCK context [] will return a block - this is what function needs. I couldn't use words (bind 'word context[]) because it wouldn't return a block.

JLCyclo
@JLCyclo
blob
@endo64 thanks, but it does not seem to work...
GiuseppeChillemi
@GiuseppeChillemi

@nedzadarek
Tried on the console

>> g: function [] bind [should-be-local] context [should-be-local: 42]
== func [][should-be-local]

What I has still not encountered is binding on a block.
I'll try to understand what we are doing, context and binding.
Here you are creating the second block of function. The second block consist of only a word which is should-be-local.
You have then created a context where should-be-local value is 42.
Then you have "linked" (bound) the context to the second function block, so should-be-local value is 42 in that context.
Function, which has become FUNC (why?) has now 2 block. An empty one, and the newly defined.

nedzadarek
@nedzadarek

@GiuseppeChillemi

function, which has become func (why?)

In the red you have "function constructors" (not sure if this is the right term). They just modifies spec and/or body argument (both are blocks) and "send" them to the func.

>> has [][]
== func [/local][]
>> does[]
== func [][]
>> func [] []
== func [][]
>> function [] []
== func [][]

Here is a little example where my newly created function constructor makes all function prints "Answer: 42":

answer-func: func [spec body] [
  insert body [print "Answer: 42"] 
  body: back body 
  func spec body
]
f: answer-func [a] [print a * 10]
f 3
; Answer: 42
; 30

g: answer-func [] [print "Hello world"]
g
; Answer: 42
; Hello world
nedzadarek
@nedzadarek

has now 2 block. An empty one, and the newly defined.

The empty one - specification (argument list, its types etc)
The newly defined - body of the function, what it does
^^ I think you understand this. What else you don't understand?

Semseddin Moldibi
@endo64
@JLCyclo Didn't work when you click on Create pull request button?
Anyway, I made a PR on behalf of you, from your fork to base: red/community#13
Semseddin Moldibi
@endo64
@JLCyclo Nice script by the way
Greg T
@gltewalt
If I feed it to itself it seems to step over all the code with step
JLCyclo
@JLCyclo
@endo64 Thanks for the PR
input "n(ext) | s(tep) | <enter>" at the prompt line runs 1 do/next command... (disadvantages: overall loops and functions)
Semseddin Moldibi
@endo64
What would be nice is to put a word somewhere in the source code and it will stop there when the execution arrives there, something like breakpoints, for example,
print 1
print 2
stop  ;execution stops here
print 3
Toomas Vooglaid
@toomasv
@nedzadarek You don't need body: back body in answer-func.
GiuseppeChillemi
@GiuseppeChillemi

When I think about code exection I lack the knowledge about how the code is interpreted, in other words, the flowing of code from load phase (lexer?), biding, interpretation and execution.
A particular aspect raises interest to me: what happens on
f-name: func [][]
or
obj-name: make object! []

I imagine that at load phase the function/object is not created but only when the "execution pointer" reachs that part and interprets it. Maybe it is in some "meta form". But I going there with my imagination.

I guess it because when I have tried to have a function with dinamyc bodies choosed by select (args and code) the select works only at when the function is called for the first time but not all the subsequents.

Boleslav Březovský
@rebolek
>> source: {f-name: func [][]}
== "f-name: func [][]"
>> data: load source
== [f-name: func [] []]
>> code: reduce data
== [func [][]]
>> length? data
== 4
>> length? code
== 1
GiuseppeChillemi
@GiuseppeChillemi
?
Why has [func [][] ] length of one ?
Boleslav Březovský
@rebolek
In data you have four values: f-name: with type set-word!, func with type word! and two empty block!s. When you execute this code, it returns one value, function!. This one value is displayed as func[][] for lack of better representation, but that doesn't mean it's three values, it's just one.
GiuseppeChillemi
@GiuseppeChillemi
And what has it become in RED internal structure ?
Boleslav Březovský
@rebolek
function!
GiuseppeChillemi
@GiuseppeChillemi
So, after that, it is no more "data" but it is something else.
What becomes "something else" after the first code run ? Objects and .. ?