by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Gregg Irwin
@greggirwin

@loziniak I'm used to parens in paths from many years of Reboling, though I don't use them often. However, they are still considered an experimental feature in Red, as we are not sure they are worth keeping.

To make sure I understand your example, you have code with 2 known values and variable key between them, like accessing a keyed record's field. Here's a more efficient way to do that, which seems clearer to me:

>> a: [b [c 123]]
== [b [c 123]]
>> k: to word! "b"
== b
>> a/:k/c
== 123

Does the path approach give you some other benefit that I don't see at a glance?

Gregg Irwin
@greggirwin
Pairs today are completely literal in their syntactic form. There is no evaluation whatsoever, which has pros and cons, and is simply a design choice. Because of the separator used (x), which is not "special" like /, it opens up a lot more questions and potential ambiguity. Paths are specifically meant for indirect access, and have to start with a word. Do pairs in your design have to start with a literal number, or is (pow 3 2)x(pow 2 3) valid as well? Because that's no longer Red compatible as a syntactic form. If that's not valid in your design, you can only evaluate the y axis, which seems much less useful and general.
Vladimir Vasilyev
@9214
Besides
>> x: make op! :as-pair
== make op! [["Combine X and Y values into a pair" 
    x [integer! f...
>> (power 3 2)x(2 ** 3)
== 9x8
Maciej Łoziński
@loziniak
@greggirwin in your example, k is not a very meaningful name for a variable. I find it clearer to use expression to word! "b" in-place. I did not think about using get-words though, because parens were first thing I tried and it worked, so I searched no more.
hiiamboris
@hiiamboris
@9214 clever! :+1:
Maciej Łoziński
@loziniak
@9214 try to do that with hypothetic coord! :-)
@greggirwin good point about syntax incompatibility of having x part of pair! defined by paren!. That kindda invalidates my idea.
Vladimir Vasilyev
@9214
@loziniak and how can I try to do that if it's hypothetical? Thought experiment?
Maciej Łoziński
@loziniak
Exactly. Just assume it's real. Brillant hack nevertheless.
Gregg Irwin
@greggirwin

:point_up: September 27, 2019 11:16 AM @9214, you're going to Hell for that. ;^) Lacking the power to send you there, I will have to concede that it's an AWFULly cool idea for a dialect.

@loziniak forgive me for not trying to come up with a more meaningful name in a short chat example. ;^)

get-field-c-from-var-a-for-rec: func [
    key [string!]
][
    key: to word! key
    a/:key/c
]
a: [b [c 123]]
get-field-c-from-var-a-for-rec "b"
Shoot, should have called it rec-id.
9214 @9214 aww jeez man.
Maciej Łoziński
@loziniak
@greggirwin Point taken, my names also don't carry much meaning. But everytime I can, I try to avoid variables like key, index etc.
GiuseppeChillemi
@GiuseppeChillemi

@greggirwin

I'm used to parens in paths from many years of Reboling, though I don't use them often. However, they are still considered an experimental feature in Red, as we are not sure they are worth keeping.

I use it a lot !

Dave Andersen
@dander
@greggirwin, here's a concrete example of using path construction (granted with all indexes in this case). It would probably be better to use word! instead of index in the cases where that is applicable, but then it would need to know if that word! was being reused in that branch of the tree...
Gabriele Santilli
@giesse
@loziniak sure, but, path! is already a block-like type, while pair! is not.
Gregg Irwin
@greggirwin
@dander path construction isn't an issue. That's an alternative, because you're making the path from other parts, not putting parens in a literal path for their evaluative property.
@GiuseppeChellemi examples?
Vladimir Vasilyev
@9214

For the reference, the main argument against paren! in paths is a stylistic one: you can abuse them with multi-line expressions or ungodly mess like inclusion of external files and deeply nested code logic.

head/(
...
<you can embed whole Red runtime here for all I care>
...
)/(
...
)/tail

One path (no pun intended) we can take is to prohibit newlines during path! lexing, thus allowing only simple, single-line expressions. Another is to get rid of them entirely.

Maciej Łoziński
@loziniak
And one more – leave it as it is now, letting a programmer choose her own style.
luce80
@luce80
@greggirwin example:
page: 1 per_page: 10

for page 1 41 1 [
    out: probe join out-head [per_page * page - per_page + 1 "-" per_page * page  ".json.txt" ]
    file: read to-rebol-file out
    probe length? file
    file: head remove/part file 3 ; remove initilal (UTF?) garbage
    json: json-to-block file
    ;probe copy/part mold json 100
    for n 2 11 1 [
        attempt[insert/only tail items json/("html")/("body")/("div")/4/("div")/("div")/("div")/2/("div")/1/("div")/("div")/1/("div")/:n/("div")/1/("div")/("span")]
    ]
    page: page + 1
    if (probe length? file) < 90 [break]; 75
]
probe count: length? items
{
probe items/2/1/("a")/1/("#text") ; creator
probe items/2/1/("a")/2/("@href") ; link
probe items/2/1/("a")/2/("strong")/("#text") ; filename
probe items/2/2/("#text") ; description
}
Gregg Irwin
@greggirwin
@luce80 thanks. String keys are probably the strongest use case for the feature.
But here is another case where doing k: "div" once, and using :k in the path would be a big win. Or :div. :^)
Gregg Irwin
@greggirwin
json/("html")/("body")/("div")/4/("div")/("div")/("div")/2/("div")/1/("div")/("div")/1/("div")/:n/("div")/1/("div")/("span")
json/("html")/("body")/:div/4/:div/:div/:div/2/:div/1/:div/:div/1/:div/:n/:div/1/:div/("span")
json/("html")/("body")/:d/4/:d/:d/:d/2/:d/1/:d/:d/1/:d/:n/:d/1/:d/("span")
Vladimir Vasilyev
@9214
Allowing strings in paths without requiring extra parenthesis would make more sense. But then we end up with the exact same stylistic argument against multi-line {...}.
Gregg Irwin
@greggirwin
Yup.
Respectech
@Respectech
I also vote to leave parens in paths. Power to the people!
Petr Krenzelok
@pekr
Ditto, found them useful sometimes ....
GiuseppeChillemi
@GiuseppeChillemi

@greggirwin use parenthesis in path to select from an another block the position of the column I am searching for in the current one:

>> columns: [cd_ar 1 description 2 orders 5]
== [cd_ar 1 description 2 orders 5]
>> values: ["C00022" "Master Market" none none "22"]
== ["C00022" "Master Market" none none "22"]
>> values/(columns/description)
== "Master Market"
>>

When column name sequence index name reflect data position I use the following form to pick the data form the right position.

>> columns: [cd_ar  description  something something-else orders]
== [cd_ar description something something-else orders]
>> values: ["C00022" "Master Market" none none "22"]
== ["C00022" "Master Market" none none "22"]
>> values/(index? find columns 'description)
== "Master Market"
>>
GiuseppeChillemi
@GiuseppeChillemi

Sometime I define an helper function to return me the right index

>>  columns: [cd_ar  description  something something-else orders]
== [cd_ar description something something-else orders]
>> values: ["C00022" "Master Market" none none "22"]
== ["C00022" "Master Market" none none "22"]
>> ps: function [column columns-pos] [index? find columns-pos column]
== func [column columns-pos][index? find columns-pos column]
>> values/(ps 'description columns)
== "Master Market"
>>

It is really useful when I navigate database data. Also I am planning more complex index retrieving experimenting with custom datatypes and their data position but I am currently in early stage as the data description language is currently building up in my mind.

GiuseppeChillemi
@GiuseppeChillemi
Also I am working on a way to access data in multiple separate blocks where each part of the path could jump to another pre-existant or computed block. This work is based on path access notation experiment created from ToomasV. All of those ways to dinamically access data blocks need parenthesis to be expressed in "serialized" form (hope the term "serialized" is used correctly here).
Beeno Tung
@beenotung
I tried to compile a hello world program w/wo -r flag,
why is the binary smaller in dev mode?
shouldn't release version be trimmed more aggressively?
Semseddin Moldibi
@endo64
@beenotung in release mode (-r) your compiled program and Red runtime are packed into one file, that's why it is bigger. In dev mode runtime is not included in your executable, that means you need to ship your program with the runtime (libRedRT.dll on Windows) otherwise it won't work.
Gregg Irwin
@greggirwin
Thanks for the examples @GiuseppeChillemi. Much appreciated.
GiuseppeChillemi
@GiuseppeChillemi
@greggirwin Your are welcome. Parenthesis impact a lot on my day to day programming style.
Palaing
@Palaing

I want to split a string (a 2-column table from a database query) with both "^-" and "^/" characters to get a flat block of items.
When the string is too long (13060 characters), the following:

split rawdata charset "^-^/"

fails with a "not enough memory" message. While this:

split replace/all rawdata  "^/" "^-" "^-"

works fine and fast.
I was just wondering why the first one would not...

hiiamboris
@hiiamboris
@Palaing what's the build you're using? I cannot reproduce the issue on Red 0.6.4 for Windows built 25-Sep-2019/22:36:30+03:00 commit #f753e25
GiuseppeChillemi
@GiuseppeChillemi
@greggirwin and I think I have just found a possible solution to access data with reusable paths. But I will need a little help from the RED team that should implement a feature to express this solution in a coincise manner.
Palaing
@Palaing
@hiiamboris I'm on Red 0.6.4 date: 3-Apr-2019/11:40:57+02:00 commit: #492254683df98fd779b4157466f54a625007d80e
(I don't change so often as I'm used to gui-console-not-starting problems)
hiiamboris
@hiiamboris
@Palaing maybe it's time to update it then ☻
Palaing
@Palaing
@hiiamboris you're right, I'm on the way. Now in step "get the antivirus to accept it's not malware"
Palaing
@Palaing
@hiiamboris thanks, the latest build fixed the issue :)
hiiamboris
@hiiamboris
:+1:
Gregg Irwin
@greggirwin
@Palaing if you update, you should now also have the CSV codec available. load/as expects commas, but the load-csv func can be used directly to specify that it's tab delimited. And has a /flat refinement.
GaryMiller
@GaryMiller
Just curious to see if anyone benchmarked the new Lex code yet. I know it's not released yet but was too excited to about it not to ask. Rough numbers are fine. Like does it seem twice as fast? Three times as fast? Be still my heart!
Gregg Irwin
@greggirwin
Have to wait for news from the inner circle. :^)
Nikita Korotkin
@TheHowdy_gitlab
(Not sure if this the right place to post this, my apologies if not)
That thing can probably be rather easily implemented in red and have about the tenth of the executable size of the original(the original is written in electron)
JacobGood1
@JacobGood1
been out of the loop, what is this lex code