by

## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
##### 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

@metaperl
Error (the Red tries to call f):

f: func [a] [a]
g: f

Good:

f: func [a] [a]
g: :f
dsunanda
@dsunanda
Not really - integers for example are neither true or false. Generally, only a logic value is true or false
true = 1
== false
false = 1
== false
Structure and Interpretation of Computer Programs
@metaperl
How do you create a 2-tuple in Red?
type? 2.3.4 versus type? 2.3
dsunanda
@dsunanda
Tuples have a mimimum of three values - 2.3 is a floating point number.
to-tuple [1 2]
== 1.2.0
Structure and Interpretation of Computer Programs
@metaperl

I dont think this guide is correct here - http://helpin.red/Datatypes.html

And any any of the following datatypes is also a scalar! datatype: char!, integer!, float!, pair!, percent!, tuple!, time!, date!

a tuple is not scalar is it?
Dave Andersen
@dander
@dsunanda they are not equivalent to the logic values, but they are considered 'truthy', because you can do if 1 ["do it"]. Only false (and related synonyms) and none are falsy
dsunanda
@dsunanda
Thanks -- technically, they are of type LOGIC! - which includes TRUE and FALSE (and ON and OFF etc)
type? false
== logic!
type? true
== logic!
A tuple in Red is a specialised datatype that can contain 3 to 12 dot separated values. The values themselves can only be 0 through 255:
>> type? 1.2.3.4.5.6.7.8.9.10.11.255
== tuple!
Dave Andersen
@dander
@metaperl pair! could be what you're looking for...
>> p: 2x3
== 2x3
>> p/x
== 2
>> p/y
== 3
Structure and Interpretation of Computer Programs
@metaperl
Is probe receiving a single block or two in this expression: probe [3 + 2] [3 + 2]
Dave Andersen
@dander
probe passes through the first value it encounters, in this case [3 + 2]. Try ? probe
Gary Miller

if I ode does
append AIResponse random/only Color
append AIResponse "!"]

I get an extra space before the "!" that is not at the end of the string inside AIResponse

Is there a way to avoid the extra spaces that append seems to add?

Ungaretti
@Ungaretti
@metaperl I think you are right. According to Red official docs "Tuple! is a member of the following typesets: immediate!, scalar!", but I don't think a typeset can be called a datatype! (?). I'll fix that when I find the time.
Gary Miller
rejoin does it ok but requires me to assign quoted string to words first which for me would be a lot of extra lines of code. I can write a function to do it but sometimes I want to concatenate different number of strings
Gary Miller

Figured it out all the examples assigned the quoted string to words but this works too.

CD: lev UserInput/text "Give me a color."
if CD < ShortestDist [ShortestDist: CD
AIResponse: rejoin ["Ok how about " random/only Color "!"]]

lepinekong
@dockimbel I didn't know about recycle/off will try. Nevertheless it's code I made a few months ago which is a big spaghetti so I'll have to refactor it anyway :)
lepinekong

do-thru doesn't seem to work with #include in this case, why ?

>> do-thru/update https://redlang.red/debug/do-thru/index.red
exist-section?: false ; instead of true
>> do https://redlang.red/debug/do-thru/index.red
exist-section?: true

index.red:

unless value? '.section [
#include https://redlang.red/section.red
]

exist-section?: value? '.section
?? exist-section?

There is no problem if index doesn't use #include:

>> do-thru/update https://redlang.red/debug/do-thru/index0.red
exist-section?: true

index0.red:

unless value? '.section [
do https://redlang.red/section.red
]

exist-section?: value? '.section
?? exist-section?
In case it matters but I don't think it matters:
.section: func [
'param>description [any-type!]
param>code [block!]
/vars param>vars [block!]
/_show
/_debug
][

_debug: false
_debug: _debug or __DEBUG_MODE__

if _debug or _show [
print ["start section" {<!--} (param>description) {-->}]
]
unless vars [
param>vars: copy []
]
do bind (param>code) make object! collect [
forall param>vars [keep to set-word! param>vars/1]
keep none
]
if _debug or _show [
print ["finish section" {<!--} (param>description) {-->}]
]
]

section: :.section
Toomas Vooglaid
@toomasv
@olivier_lp_twitter Do you mean something like:
view [field all-over on-down [probe event/offset]]
Toomas Vooglaid
@toomasv
Er.. all-over is irrelevant ^
LP Olivier
@toomasv no, i mean by cursor offset, is when i'm filling the field the cursor is moving forward one char by one char, I'm tryning to filter a drop-down list while filling the face/text value but it always put the cursor at the beginning of the text
Structure and Interpretation of Computer Programs
@metaperl

Other languages have a data type called array. It is not difficult to realize that a one dimensional array is simply a series, and multi-dimensional arrays are series that contain other series as elements.

but the question is: "is this an efficient way to process multi-dimensional arrays"?

@dockimbel

a one dimensional array is simply a series

That's not true. A series is the combination of a collection and an head offset. That is not exactly the "array" datastructure found in other languages.

@metaperl

"is this an efficient way to process multi-dimensional arrays"?

Define "efficient". It depends what you want to do. I guess if you want to create many small arrays then "series in the series" would use more memory (not tested). You have to test it. btw. SERIES! is a typeset! value: make typeset! [block! paren! string! file! url! path! lit-path! set-path! get-path! vector! hash! binary! tag! email! image!] and one user used image! for storing 2D arrays... so, test it.

Toomas Vooglaid
@toomasv
view [
size 180x190
below
fl: field 100
extra ["one" "two" "three" "four" "five" "six" "seven" "eight" "nine" "ten"]
on-focus [
tl/data: face/extra
tl/selected: either found: find tl/data face/text [index? found][1]
tl/visible?: yes
]
on-enter [face/text: copy pick tl/data tl/selected tl/visible?: no]
on-change [
tl/visible?: yes
either empty? face/text [
tl/data: face/extra
][
tl/data: collect [
foreach element face/extra [
if find/match element face/text [keep copy element]
]
]
]
tl/selected: 1
]
at 0x0 tl: text-list hidden data []
on-change [fl/text: copy pick face/data face/selected]
do [tl/offset: fl/offset + 0x24]
]
Structure and Interpretation of Computer Programs
@metaperl
How would I convert this Scheme to Red: (+ 21 35 12 7)
i.e. - apply a binary operator to a series of values
@9214
scheme: function [:s-expr [paren!]][
op: take s-expr
do next collect [
forall s-expr [keep op keep s-expr/1]
]
]
>> scheme (+ 21 35 12 7)
== 75
Structure and Interpretation of Computer Programs
@metaperl
I want to load this file so that my-abs is in memory and then type my-abs -12 and see the result... load and do dont seem to add my-abs to memory.
@9214 I'm sorry ... I shouldve made myself clearer... what if I had nums: [21 35 12 7] and then I wanted to sum them up... preferably without using sum but rather with something that applies + to all elements of a block
@9214
@metaperl there's no apply native yet, so you can just insert + in-between elements and then do everything. The idea is the same as I showed above.
Not sure what you mean by "memory". doing script should behave as you expect.
>> do https://raw.githubusercontent.com/metaperl/sicp-red/master/ch1/abs.rd
== func [x][either (x >= 0) [x] [x * -1]]
>> my-abs -5
== 5
Gabriele Santilli
@giesse

@metaperl I believe you're looking for something like this?

>> accumulate: function [zero f list] [foreach n list [zero: f zero n] zero]
== func [zero f list /local n][foreach n list [zero: f zero n] zero]
>> accumulate 0 :add [21 35 12 7]
== 75

Perhaps it there should be a more general version of collect, however in practice it may not be worth it.

Structure and Interpretation of Computer Programs
@metaperl

I will check on that in a second.... I have a new question.

I am trying to implement the sqrt-iter function shown here

But I am getting a cryptic error message when I try to call my-sqrt 9 in my code

wow, that is pretty cool @giesse
@9214

@metaperl FYI, before you delve into SICP too deep - you should realise that Red is different from Scheme in many aspects, and one of them are "scoping" rules. Scheme has a lexical scope with deep binding of function's bodies (so you get closures for free and can write in idiomatic FP style as in the book). Red doesn't have scopes at all, and its concept of "binding" is a bit different from other languages. Another thing to keep in mind is that we don't have tail-call optimization yet, so you'll blow up the stack rather quickly writing in Scheme style.

I think you'll manage to complete first two chapters, but part with lambda calculus will get tricky (although at that point we might get a closure! datatype). Third part should be tackled in a more idiomatic way - with object!s and block!s, and specific care should be taken with "mutable data" section. As for concurrency and streams - thunk is a "freezed" evaluation, which is just a block!. Streams can be build on top of them rather easily.

I haven't read 4th and 5th chapters, but 4th one should be definitely tackled with Parse, and with 5th you might go Rambo and study Red/System :wink:

@9214
Here's my rewrite:
sqrt-iter: func [guess x][
either good-enough? guess x [guess][
sqrt-iter improve guess x x
]
]

improve: func [guess x][average guess x / guess]

average: func [x y][divide x + y 2]

good-enough?: func [guess x][
lesser?
absolute subtract guess * guess x
0.001
]

sqrt: func [x][sqrt-iter 1.0 x]
On a quick review, I think your improve function should be changed to:
improve: func [guess x] [average reduce [guess (x / guess)]]
PavelVozenilek
@PavelVozenilek
I am reading a discussion about Red on Hacker News, and there's very useful explanation, possibly worth to be linked from somewhere:
https://news.ycombinator.com/item?id=18866864
@9214
@PavelVozenilek (author here) thanks! I plan to extend it into a dedicated blog post at some point. Your feedback is appreciated, as newcomers and newbies alike are the main target audience.
PavelVozenilek
@PavelVozenilek
@9214 : Heh. I am trying to grok Red and the documentation is a torture.
@9214
@PavelVozenilek fair enough. We have a list of learning resources to get you started. I'd recommend to pick Rebol/Core user guide first, and follow it through with this wiki page.
You can always ask questions here or in /welcome room - someone will always jump in to give a guiding hand.
Greg T
@gltewalt
@PavelVozenilek Which documentation is a torture?
Gregg Irwin
@greggirwin
@9214, WRT your messages: https://gitter.im/red/help?at=5c345e9957c6883f9b7ebf72 and https://gitter.im/red/help?at=5c34826026d86e4d5643e372 to @nedzadarek, understand that you are expected to abide by our codes of conduct, per the link @gltewalt posted. This is a warning.
hiiamboris
@hiiamboris
Hi! Any ideas how to turn window's event/offset into a face object at that offset? (apart from looping thru all faces)
@hiiamboris If you have access to the event object, then just event/face. If you want to avoid looping, then there's a get-child-xy function in the GUI backends, that would return you a face object from a pair of coordinates. But those are OS-specfic functions, so their interface may vary with the OS.