Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jul 01 2018 17:34
    @greggirwin banned @BIjeuca_twitter
  • Dec 03 2017 05:53
    @PeterWAWood banned @matrixbot
  • Sep 28 2016 12:20
    @PeterWAWood banned @TimeSeriesLord
hiiamboris
@hiiamboris
tail a is e
and yes, it's better not to use any set-words in those rules, as.. global namespace pollution when interpreted
Toomas Vooglaid
@toomasv

Thanks @hiiamboris Here is version without global words:

save/header %tmp.red [
    #macro [ahead paren! into ['f some integer!]] 
    func [[manual] s e][change/only/part at s/1 2 to-block at s/1 2 tail s/1 s] 
    probe (f 1 2) 
    probe (f 10 20 30)
][]
do %tmp.red
;3
;60
;== 60

NB! tail a is not e

hiiamboris
@hiiamboris
s/1 wouldn't be more readable? ;)

NB! tail a is not e

Riiight. Good catch.

Toomas Vooglaid
@toomasv
Yes, thanks, corrected!
Toomas Vooglaid
@toomasv
From last version function f itself was left out. Insert this before first probe::
f: func [blk [block!]][sum blk]
Gregg Irwin
@greggirwin
Respectech
@Respectech
Sounds good to me.
Gregg Irwin
@greggirwin

Thanks @Respectech.

@toomasv, the macro approach is cool, but some integer! probably isn't that useful as a rule. :^) I think this is where evaluation complicates var-args in Red. Not that we can't solve it technically, but they may end up being harder to read, especially if any lit args are involved.

Toomas Vooglaid
@toomasv
I agree that this in itself in not much worth, it was just interesting adventure into macros.
Gregg Irwin
@greggirwin
Toomas Vooglaid
@toomasv
Hmm, the kind of thing I did is discouraged in starting note there, so maybe not to push in this direction?
Gregg Irwin
@greggirwin
We can probably add examples, with caveat emptor clauses. :^)
As you noted, this is about exploration and learning.
hiiamboris
@hiiamboris

Well,

There is nothing macros can do that you can't do with regular code, with the same expressive power. Macro support in interpreted code is just for compatibility with the compiler.

I have already collected a bunch of macro solutions that disprove the above statement ;)

Gregg Irwin
@greggirwin
Good thing it's a wiki then.
lylgithub2021
@lylgithub2021
Thank you.@greggirwin Refinement is too heavy for some matter. To pass blocks of values is the easist way, but seems not quite elegant. I don't quite unserstand "free ranging evaluation". Further info or examples would be highly appreciated!
Gregg Irwin
@greggirwin
Free ranging evaluation just means there are no parens around args for function calls. So you can't tell when an expression ends without knowing how many args each piece consumes, and whether they themselves are evaluated. As far as being elegant, is Lisp an less so just because the bracket is one token to the left? (my-fn 1 2 3) vs my-fn [1 2 3].
lylgithub2021
@lylgithub2021
@toomasv I tried your code save/header...do %tmp.red, but get message *** Script Error: f has no value, why?
Toomas Vooglaid
@toomasv
@lylgithub2021 :point_up: April 14, 2021 4:41 PM
lylgithub2021
@lylgithub2021
image.png
@toomasv
Toomas Vooglaid
@toomasv
@lylgithub2021 Do you use latest nightly build?
image.png
lylgithub2021
@lylgithub2021
image.png
hiiamboris
@hiiamboris
That's what happens when you type the code instead of copy-pasting (:
Toomas Vooglaid
@toomasv
@lylgithub2021 Ah, yes, into ['f .... Thanks, @hiiamboris!
lylgithub2021
@lylgithub2021
Thanks! @toomasv @hiiamboris
Toomas Vooglaid
@toomasv
:+1:
lylgithub2021
@lylgithub2021
Both file name and file path are dataype of file! in Red language. Is there any function or other way to tell whether a file! is a file or a path?
hiiamboris
@hiiamboris
not in runtime
you just need to check the first char
lylgithub2021
@lylgithub2021
chck the first char seems to fail in checking all returns in read %. whose path contain sub-directory .
hiiamboris
@hiiamboris
ah
so maybe you're just looking for dir??
lylgithub2021
@lylgithub2021
Yes, It is. Many thanks! And, is there a way to convert a reletive path to absolute path?
dsunanda
@dsunanda
a way to convert a reletive path to absolute path
 clean-path %rel/path
lylgithub2021
@lylgithub2021
It seems that the returned absolute path refers to the current working path, not always the real file path.
No function such like "red-complete-path" in Red to acquire the real absolute path?
Gregg Irwin
@greggirwin
If you have a relative path, it has to use something as a base to make an absolute path out of it, so I'm not sure what you mean by "the real absolute path".
lylgithub2021
@lylgithub2021

@greggirwin I'd like to list all files in a given directory(which contains sub-directories) to a block with this:

Red []
all-files: function [dir] [
collect [
  foreach i read dir [keep 
    either dir? i
    [all-files i]
    [i]
]]]

The return of all-files just give file names, but absolute file path is also needed for the reason of later file loading. This is why I want to convert a relative file path to a absolute path.

Gregg Irwin
@greggirwin
There are a number of tree loaders people have done. If you need absolute paths in a flat list, you need to prepend the current dir as you walk.
Gregg Irwin
@greggirwin
Something like this:
all-files: function [
    {Returns a block of fully qualified filenames for the directory.}
    spec  [file!]   "Starting Directory"
    block [block!]  "Block to append to"
    /deep           "Recurse sub-directories."
][
    spec: dirize spec
    foreach file read spec [
        f-spec: repend copy spec file
        either all [deep dir? f-spec] [
            all-files/deep f-spec block
        ][
            append block f-spec
        ]
    ]
    block
]
In this version, if you pass a relative path as the spec, that's used. If you pass an absolute path, that's used, so you are in control. If you want to use clean-path your walker needs to change to the current dir you're reading as it goes.
lylgithub2021
@lylgithub2021
@greggirwin Many thanks for your code!!
lylgithub2021
@lylgithub2021
And, given a relevant directory(maybe not current working dir), how to get its real absolute path in Red?
hiiamboris
@hiiamboris
Two people already gave you the function to do that :)
hiiamboris
@hiiamboris
I guess the docstring could be more specific about it though.