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
Gregg Irwin
@greggirwin
Dialects are also a major pattern for preventing code injection. You will likely never be able to safely do untrusted code.
Nenad Rakocevic
@dockimbel
@gltewalt do cannot be secured, but it should be possible to sandbox untrusted code, by blocking some language features.
GiuseppeChillemi
@GiuseppeChillemi
Now that I have understood "there is no spoon" I want to move to the next step: how is the code interpreted ? From loading the script to the very first steps
Gregg Irwin
@greggirwin

@GiuseppeChillemi, lexical scanning is the first step. Parsing and tokenizing the input to find Red values in the text, and determining if the input is valid. That is, it contains all valid Red values.

At that point you have a block of values. Think about how you, as a human, interpret that. You know some values are direct values, like numbers. But what happens when you find a word? You need to determine what to do. What kind of word is it? What is the behavior of each kind of word?

David Viner
@RiVeND
@greggirwin Thanks for that, Gregg :thumbsup: . I always find I have better comprehension of a system if I can picture what's going on under the hood. Maybe, when the documentation efforts get off the ground, those with more in-depth knowledge of Red could produce some simple flowcharts of what the more complex parts do (such as parse). I know they would definitely help me get a better grip on the language.
Gregg Irwin
@greggirwin

Glad if it helped a bit @RiVeND. Parse is deep, and hard to describe in prose/text, because the behavior and data mixture will be verbose. An interactive tool will be much better, so you can see what rule is being evaluated, the current location in the input, and maybe hints about keyword behavior. e.g. if ahead is evaluated, a "does not advance" indicator could light up.

There was an old parsing tool, VisualParse++, from Sandstone technology, that did something like that. It was a shift-reduce parsing tool, and was pretty cool.

GiuseppeChillemi
@GiuseppeChillemi
How datatypes are associated to each element of the block ?
Dave Andersen
@dander
@GiuseppeChillemi the elements of a block are all values, and every value has a type. All values in Red are 'boxed', and the box contains both the type and data structure which represents the value
Gregg Irwin
@greggirwin
@GiuseppeChillemi, to add to @dander's answer, you can think of blocks as having "value slots" that refer to values. The block doesn't know, or care, what type of value is in each slot.
Mårten Hildell
@MartenH

Hi
I'm new to the language and I'm trying to do something that I think is quite simple, but I fail.
I just want to convert a hexadecimal byte that is on string format to a binary value.

Something that works:

t: #"^(AB)"
a: to binary! to-hex/size (to integer! t) 2
print a

I now want to "construct" t so that "AB" can be a string, ie construct a character from a string if that makes any sense.

I know that are other ways to do this but this got interesting.

Vladimir Vasilyev
@9214
?
>> skip to binary! #"^(AB)" 1
== #{AB}
idk if that will work for you in general case
Nenad Rakocevic
@dockimbel
@MartenH
t: #"^(AB)"
append a: #{} to-integer t

== #{AB}

construct a character from a string

A string is composed of characters, so such wording doesn't make much sense in this context. You might want to extract a character from a string rather.

Mårten Hildell
@MartenH

Thanks for the responses.
I'm know I'm missing something fundamental but I still don't understand how to create t in this case.

Assume "AB" is held in a string! how to I create t ?

str: "AB"
t: ????
Petr Krenzelok
@pekr
load rejoin ["#{" "AB" "}"] ; though not sure it is a safe aproach ...
Vladimir Vasilyev
@9214
@MartenH
>> str: "AB"
>> load rejoin [{#"^^(} str {)"}]
== #"«"
ah, @pekr was faster :)
Mårten Hildell
@MartenH
Thanks a lot! Was looking for something like "rejoin" , but I could not find it:http://static.red-lang.org/red-system-specs-light.html nor here...http://www.red-by-example.org/ . Again, thanks.
Mårten Hildell
@MartenH
More things I don't understand, in this case why I would need paranthesis around a.
I simply do not understand the difference
>> t: "12345"
== "12345"
>> repeat a length? t [ print t/a ]
*** Script Error: word! type is not allowed here
*** Where: print
*** Stack:  

>> repeat a length? t [ print t/(a) ]
1
2
3
4
5
>>
Toomas Vooglaid
@toomasv
@MartenH Without parenthesis, path notation seeks literal a, but inside parens a is first evaluated to number and only then path is accessed. String is series, and you can access its elements by index numbers but not by literal words. Other structures can be accessed by words, e.g.:
>> t: [a b c]
== [a b c]
>> t/a
== b
>> t: #(a: 1 b: 2)
== #(
    a: 1
    b: 2
)
>> t/a
== 1
>> t: object [a: 1 b: 2]
== make object! [
    a: 1
    b: 2
]
>> t/a
== 1
Petr Krenzelok
@pekr
repeat a length? t [print t/:a]
Vladimir Vasilyev
@9214
forall t [print first t]
Mårten Hildell
@MartenH
Seems I have been coding C for too long...
DVL333
@DVL333
I want to create form with flags (for example, "resize") and options ("menu"). I know how to do it separately, but how to combine them together for the form?
view/options [][menu: ["a" "b" "c"] ]
view/flags [] ['resize 'modal]
Nathan Douglas
@nd9600
Is there a way to have error messages tell you what line they were thrown from? I can only see "Where: append" right now, and I've a lot of appends in my script, so it's a bit hard to debug
Greg T
@gltewalt
@MartenH take a look at pad it might help with what you want
Toomas Vooglaid
@toomasv
@nd9600 I think this is the way:
view/options/flags [][menu: ["a" "b" "c"]]['resize 'modal]
Gregg Irwin
@greggirwin
@MartenH, you'll find your feet in Red soon enough. Just keep asking questions when you need to, and save some time.
@DVL333, I think @toomasv meant to tag you in his answer.
Gregg Irwin
@greggirwin
@nd9600, there is no line information in errors. It would come up at times in the Rebol community, but I haven't seen it requested for Red yet. It's tricky, and Carl talked about it at one point, because there isn't always a concept of "lines". That is, Red doesn't need to maintain new line markers for processing in loaded code. Practically speaking, we use them a lot.
DVL333
@DVL333
@toomasv @greggirwin Yes, i've tried it - OK. Thank you very much!
Toomas Vooglaid
@toomasv
@greggirwin Thanks! :blush:
Mårten Hildell
@MartenH
@gltewalt @toomasv @9214 @greggirwin Thanks..
Greg T
@gltewalt
I was confused earlier. I might still be unclear on what is expected, but - @MartenH is this the result that you were looking for?
>> str: "AB"
== "AB"
>> t: enbase/base str 2
== "0100000101000010"
Vladimir Vasilyev
@9214

@MartenH

Thanks a lot! Was looking for something like "rejoin" , but I could not find it:http://static.red-lang.org/red-system-specs-light.html

on a side note - you shouldn't look at R/S docs, because they are not about Red, but about Red/System, a low level dialect. Here's a list of learning resources, but you also should get familiar with probe, source, help, what, ? and ?? functions.

Greg T
@gltewalt
Best list of all time
RnBrgn
@RnBrgn

@greggirwin

@nd9600, there is no line information in errors. It would come up at times in the Rebol community, but I haven't seen it requested for Red yet. It's tricky, and Carl talked about it at one point, because there isn't always a concept of "lines". That is, Red doesn't need to maintain new line markers for processing in loaded code. Practically speaking, we use them a lot.

Greg, if Red code is just data , why can't the error indicate which element "#" in the series code block the error happened at?

Mårten Hildell
@MartenH
@9214 I'm actually a bit confused about what is in the R/S and in Red. The R/S specification is really good but for specific Red things (#system, etc) I find myself digging in the examples..it will come to me I guess.
Vladimir Vasilyev
@9214
R/S -> C, Red -> Rebol + Forth + Lisp + turtles all the way down
Mårten Hildell
@MartenH
@gltewalt Nope. What I have a string of byte values, so "AB12CD" should become #{AB12CD}. Did @pekr solution and that worked fine..
Is there a "/local" for block scope? I now use things like "t: copy []" to clear things...
Dave Andersen
@dander
@MartenH there is also debase for converting a binary coded string into a binary value: debase/base "AB12CD" 16 (default is base 64)
Mårten Hildell
@MartenH
@dander Yes, that was indeed simpler...
Dave Andersen
@dander
There isn't really such a thing as "block scope" in Red. Each word in independently bound to a context, and some things like functions will bind all the words of their body to a new context, which works a lot like having a function scope. It is one of the deeper topics to dig into, but depending on how far deep you want to go, there are some articles from Rebol on "bindology" that explain it pretty well
Vladimir Vasilyev
@9214
@MartenH not sure what you mean by "block scope"
Mårten Hildell
@MartenH

@9214 I used the /local in a block and thought it would be the same thing as in C, but it
has function scope and not block scope....

In C this would be:

if( ..) {
   uint32_t hello;
   hello = 1;
}

hello variable would only live in the if block.

Vladimir Vasilyev
@9214
@MartenH I dont' know C that much, but here's the thing - C has lexical scoping, but Red has no scopes at all
Nenad Rakocevic
@dockimbel
@MartenH I strongly suggest reading the Rebol/Core Manual, if you haven't done so yet. You cannot understand Red language from R/S documentation.