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
Oldes Huhuman
@Oldes
ok.. so it's word!, question is same... the doc string for reduce is: {Returns a copy of a block, evaluating all expressions}
Rebol simply reduces only block... but let's pass any other value thru it without error.
Oldes Huhuman
@Oldes
Carl said: Anyway, the reason it's important is that REDUCE is a primary, high-frequency native, so I like to keep them lean and fast.
It's easy to make it compatible with Red in this case... question is if it's really worth to. Especially when one can use get in such a situation, which is more clear to me.
GiuseppeChillemi
@GiuseppeChillemi
I prefer Red behavior as it is what you expect from this sequence:
M: 1
FIRST [M] -> M
REDUCE M
== 1
However Rebol has an interesting feature that I have not noticed during the past 2 decades:
/only -- Only evaluate words and paths, not functions
 words -- Optional words that are not evaluated (keywords) (Type: block none)
Oldes Huhuman
@Oldes
Instead of REDUCE M in your sequence above you can write just M and you will get 1 too.
>> reduce probe m
1
== 1
GiuseppeChillemi
@GiuseppeChillemi
It's not a REPL sequence but a mental sequence.
Oldes Huhuman
@Oldes
You should ask yourself how many times you will use reduce first blk (I never used it) and if it's really worth to add at least 2 datatype checks with evaluation branches (don't know how it's done in Red, but that is what would be needed to do in R3).. into frequently used function.
But I agree, it's worth to be documented ;-) Going to sleep.
Oldes Huhuman
@Oldes
Btw... you can also use:
do/next [m] 'n
== 1
b: [m m + 1] m: 1
do/next b 'b
;== 1
do/next b 'b
;== 2
which is more reasonable than doing reduce first b (at least for my tired mental sequence)
Gregg Irwin
@greggirwin
Definitely add all that to the Rebol/Red differences wiki page.
John Paul Wohlscheid
@JohnBlood_gitlab
So, I'm trying to learn Red. I used VSCode to compile hello-gui.red. When I ran the .exe, it flashed and disappeared. I'm not sure if it worked correctly. Is there a way to keep the window up until I close it?
Gregg Irwin
@greggirwin
I haven't used VSCode in a long time, but I can fire it up if nobody else chimes in. You should be able to capture the compiler output and see it in VSCode. Most editors support this anyway. Unless you mean %hello-gui.exe disappears when you run it, in which case running it from a terminal might provide a clue. Then also let us know what version of Red you're using, and if you used -c or -r. If you aren't already, use -r (or -u`) to make sure it's not a runtime issue with an old build, and also use the automated build rather than the (very old) stable build of Red.
Also let us know if the Red GUI console works on your system.
Greg T
@gltewalt
quarantined? If you have an antivirus, it's probably munching it.
I have a distant, hazy memory of trying to run an .exe and having it flash and disappear... and I want to say that it was the AV
Dmitry Bubnenkov
@bubnenkoff
How to get current process PID from itself?
Dmitry Bubnenkov
@bubnenkoff
>> process-id?
*** Script Error: process-id? has no value
Boleslav Březovský
@rebolek
Interesting question. I don't think it's possible currently, but I would expect it to be part of system object. You probably should make a wish.
Dmitry Bubnenkov
@bubnenkoff
hot to get access to system?
Petr Krenzelok
@pekr
help system, help system/view, etc.
It's just an object structure imo, imagine Windows registry without an unnecessary mess :-)
Boleslav Březovský
@rebolek
Yes, it's an object with a lot of useful info, like /proc/ dir on Linux.
zwortex
@zwortex

Hi everyone, happy new year also.

A question related to the gui.

In the following code, I display a matrix of buttons with one particular button being twice as high as the others, followed by two full width text fields.

lay: layout [
    origin 10x10
    space 1x1
    style b: button 72x38 font-size 12
    ; default space of 1 turns as 3 pixels high in my display
    b "1" b "2" b "3" b "4" return
    ; twice high is 38*2 + 3 = 
    b "5" b "6" b "7" b "8" 72x79 return
    ; (1) this row should be shifted to the top from 38 + 3 (button height + space height)
    pad 0x-41 b "1" b "2" b "3" return
    ; lets add a full width field - width is 72*4 + 3*3 = 297
    ; (2) correct field row that is one pixel to the left compared with buttons
    pad 1x0 field 297x38 orange font-size 16 "F1" return
    ; (3) correct further gap between field widget and text widget that is 2 pixels high and not 3
    pad 1x1 text 297x38 green "F2" return
]
view/no-wait lay

; for a dump of the window
; img: to-image lay
; save/as %layout.png img 'png

Firstly, I understand the need for padding the third row of buttons to account for the higher button (1), but I don't get it why the text fields and buttons are not aligned on the left (2). I don't get it either why field and text widgets are not 3 pixels apart like the buttons, or the buttons and the field (3).

Secondly, I suspect that all this hard work will be useless in a different environment (other resolution and other system). My environment is Windows 10 / x64 / 1920x1080. How can I enforce this layout in all situations ? Cheers.

hiiamboris
@hiiamboris
Rounding error.
I get 4px gap some places from your layout.
(2) due to OS decoration differences of each face (View corrects for that to some extent)
(3) each pair in the layout gets normalized to current DPI setting in the OS, and since pairs are integer-only (so are OS widget positions), there's a slight inaccuracy
Dmitry Bubnenkov
@bubnenkoff

Yes, it's an object with a lot of useful info, like /proc/ dir on Linux.

On Windows I do not see nothing related with PID. Which section I should to check?

Oldes Huhuman
@Oldes
@bubnenkoff write a routine using GetCurrentProcessId from Kernel32.dll on Windows.
Dmitry Bubnenkov
@bubnenkoff

@bubnenkoff write a routine using GetCurrentProcessId from Kernel32.dll on Windows.

it's only way?

Oldes Huhuman
@Oldes
Yes. But it cannot be easier. It's just a function which returns a number.
@rebolek any idea in which system object section it should be?
@bubnenkoff it's already used internally as a part of View... it's just not accessible from Red.
Oldes Huhuman
@Oldes
@bubnenkoff it's even mentioned in the Red/System document.
Dmitry Bubnenkov
@bubnenkoff

I tried to compile example:

Red []

#import [
   "kernel32.dll" stdcall [
       process-id?: "GetCurrentProcessId" [
           return: [integer!]
       ]
       get-env: "GetEnvironmentVariableA" [
           name    [c-string!]
           buffer  [c-string!]
           size    [integer!]
           return: [integer!]
       ]
   ]
]

pid: process-id?

and got error: undefined word process-id?
It's error in example oк I forget how to interact with r/s code?

Oldes Huhuman
@Oldes
The example is for Red/System code... you must learn how to make a routine!
Dmitry Bubnenkov
@bubnenkoff
Oh! Your are right!
Dmitry Bubnenkov
@bubnenkoff
I did it! Not sure that it best way, but it work:
Red []
#system [
    #import [
           "kernel32.dll" stdcall [
               process-id?: "GetCurrentProcessId" [
                   return: [integer!]
               ]
        ] 
    ]
    _pid: func[return: [integer!]] [return process-id?]
]

get-pid: routine [/local pid [integer!] ] [
        pid: _pid
        print pid
    ]

get-pid
hiiamboris
@hiiamboris
:clap:
Dmitry Bubnenkov
@bubnenkoff
Link to working solution if anybody world search here https://gitter.im/red/red/system?at=6000993a14cec811ec9b261a
John Paul Wohlscheid
@JohnBlood_gitlab

I haven't used VSCode in a long time, but I can fire it up if nobody else chimes in.

@greggirwin Turns out that I put a colon after text and it was causing an error.

zwortex
@zwortex

As mentioned in red/bugs. How do you create parse rule with dynamic values ?

I tried using compose to mix a static rule with some dynamic values, like with view. However as parenthesis are useful in parse dialect, it quickly becomes messy. I ended up using to-paren all the times which makes the rules hard to read.

Maybe there is another way ? Compose with a different delimiter ?

keys: #(
    k1: ['k1 'Key1]
    k2: ['k2 'Key2]
)
rule: compose [
   (keys/k1/1) keep ( to-paren keys/k1/2 )
   | (keys/k2/1) keep ( to-paren keys/k2/2 )
]
s: copy []
parse [k1 k1 k2] [collect into s [any rule]]
probe s

I also tried generating the rule dynamically :

keys: #(
    k1: ['k1 'Key1]
    k2: ['k2 'Key2]
)
rule: do [
    b: copy []
    foreach v values-of keys [
        append b reduce [v/1 'keep to-paren v/2 '| ]
    ]
    take/last b
    b
]
s: copy []
parse [k1 k1 k2] [collect into s [any rule]]
probe s

Though it is fine for creating a rule with multiple alternate, it is not that useful for twisting a bunch of static rules with few dynamic values.

Then I thought I could do some sort of meta parsing and twist the rules before using them. I was tempted to use !tag datatype for implementing delimiters for values to replace.

keys: #(
    k1: ['k1 'Key1]
    k2: ['k2 'Key2]
)
rule: [
   <keys/k1/1> keep ( <keys/k1/2> ) | 
   <keys/k2/1> keep ( <keys/k2/2> )
]
; meta-parse the rule
meta: [ any [ item ] ]
item: [ s: tag! ( change s reduce load to-string s/1 ) | ahead [ block! | paren! ] into meta |  skip ]
parse rule [ meta ]
probe rule
; parse
s: copy []
parse [k1 k1 k2] [collect into s [any rule]]
probe s

Are there any other strategies to consider for injecting dynamism into parse rules ?

this is what I'm using
parse rules is a great use case btw