Giveaway winner

Sep. 23rd, 2017 03:29 pm
[syndicated profile] forgotten_bookmarks_feed
This week's giveaway winner was @Lovely_Lady_Bee, who entered on Twitter.

Thanks to all who entered, see you here next week.
[syndicated profile] rebol_questions_feed

Posted by rnso

I want to convert many decimal numbers available as strings to floats in one go. I am trying following code which combines these strings into a series and then convert them to floats. This works all right but fails if there is an error:

a: "1.5" 
b: ""
c: "3.7"
invars: [a b c]

print a
print type? a

set invars foreach x invars [append [] to-float reduce x]  ; code to convert string series to float series; 

print a
print type? a

The error is:

*** Script Error: cannot MAKE/TO float! from: ""
*** Where: to
*** Stack: to-float 

For error correction, I tried following code:

temp: []
foreach x invars [
    y: copy ""
    either error? [set [y] to-float reduce x]
        [append temp reduce x]         ; put original value if not convertable
        [append temp reduce y]  ]
print temp 
set invars temp
print a 
print type? a

But this is also not working. Where is the problem and how can this be corrected?

Comic for September 23, 2017

Sep. 23rd, 2017 11:59 pm
[syndicated profile] dilbert_feed
Dilbert readers - Please visit Dilbert.com to read this feature. Due to changes with our feeds, we are now making this RSS feed a link to Dilbert.com.
[syndicated profile] rebol_questions_feed

Posted by rnso

I want to alter a series of variables from a loop, but the following code is not working:

a: 10
b: 20
c: 30
print reduce [a b c]              ; output is 10 20 30 as expected

varnames: [a b c]                 ; make a series of variables
foreach i varnames [              ; loop to convert each to 0
    i: 0
]

print "After conversion loop: "
print reduce [a b c]              ; values are still 10 20 30 (expected 0 0 0)

After running this code, I'd expect the values of a, b, c to be changed, but they're not:

>> print reduce [a b c]   
10 20 30

Where is the problem?

[syndicated profile] rebol_questions_feed

Posted by rnso

I want to get values from 2 series into one but it is not working:

I have 2 series:

a: [1 2 3]
b: [4 5 6 7]

I want to get all values in one list, so that I can access them as allv/1, allv/2... allv/7.

Following is not working since it makes a series of series and not series of values:

allv:  [a b]
print allv     ; => prints all 6 values, but following do not work: 
print allv/1   ; => gives a  (desired is 1)
print allv/2   ; => gives b  (desired is 2)
print allv/3   ; => gives none (desired is 3)

I tried following function to combine values in one series:

mycombine: function [ll][
    temp: []
    foreach l ll [
        repeat i length? l [
            temp: append temp l/:i ] ]
    temp]

mycombine [a b]

But above gives error:

*** Script Error: length? does not allow word! for its series argument
*** Where: length?
*** Stack: rncombine 

The series has got converted into word and is not working.

How can I solve this?

Comic for September 22, 2017

Sep. 22nd, 2017 11:59 pm
[syndicated profile] dilbert_feed
Dilbert readers - Please visit Dilbert.com to read this feature. Due to changes with our feeds, we are now making this RSS feed a link to Dilbert.com.
[syndicated profile] rebol_questions_feed

Posted by rnso

I have strings in a namelist, that correspond to variables as well as field names in the application.

The function should read strings from namelist, add an 'f' to get field_names, and then put variable values in corresponding fields.

I tried following code, that does not give any error, but also does not work:

namelist: ["var1" "var2"]
var1: 5
var2: 10

process: [
    repeat i length? namelist [
        (to-set-path compose rejoin [namelist/:i "f/text"] (to-word namelist/:i))
    ]
]

lay: layout [ 
    text "Values to appear here: "
    var1f: field "a"
    var2f: field "b"

    button "Click" [do process]
]

view lay

Locked

Sep. 21st, 2017 03:02 pm
[syndicated profile] forgotten_bookmarks_feed
Key.

Found in "The Path of Thunder" by Peter Abrahams. Published by Harper, 1948.


-Click to enlarge photos-

Comic for September 21, 2017

Sep. 21st, 2017 11:59 pm
[syndicated profile] dilbert_feed
Dilbert readers - Please visit Dilbert.com to read this feature. Due to changes with our feeds, we are now making this RSS feed a link to Dilbert.com.
[syndicated profile] rebol_questions_feed

Posted by rnso

I want to remove all characters in a string except:

  • - or _ or .
  • A thru Z
  • a thru z
  • 0 to 9
  • space

On linux command line, using sed I would do this:

$ echo "testing-#$% yes.no" | sed 's/[^-_.a-zA-Z0-9 ]//g'

Output:

testing- yes.no

How can I achieve the same effect in Red language with PARSE? I looked at:

However, I could not codify it. I tried:

>> parse "mystring%^&" [#a - #z #A - #Z #0 - #9]
== false
>> parse "mystring%^&" [#a-#z#A-#Z#0-#9]        
== false

Not Forgotten Part XIII

Sep. 20th, 2017 05:15 pm
[syndicated profile] forgotten_bookmarks_feed
Yet another installment! Here are parts one, twothreefourfivesix, seveneightnine, teneleven and twelve of this ongoing series where I feature some of the items I find that aren't quite good enough for their own post. Enjoy!






-Click to enlarge photos-
[syndicated profile] rebol_questions_feed

Posted by rnso

I am trying following code to read values from a list to be put into field elements which are also placed in another list:

Red [needs: view]

view [
    text "N1:"
    ff: field ""
    text "N2:"
    gg: field ""

    do [fldlist: [ff gg] 
        vv: 5  ww: 10
        varlist: [vv ww]   ]

    button "Click" [
        repeat i (length? varlist) 
            [to-set-path to-word fldlist/i/text:  varlist/:i]  ] ]

However, it is not working. The error is:

*** Script Error: path fldlist/i/text: is not valid for none! type
*** Where: set-path
*** Stack: view do-events do-actor do-safe to-set-path to-word 

I also tried :i (i) and (:i) instead of just i but it is not working. Where is the problem and how can it be solved? Thanks for your help.

Comic for September 20, 2017

Sep. 20th, 2017 11:59 pm
[syndicated profile] dilbert_feed
Dilbert readers - Please visit Dilbert.com to read this feature. Due to changes with our feeds, we are now making this RSS feed a link to Dilbert.com.

Comic for September 19, 2017

Sep. 19th, 2017 11:59 pm
[syndicated profile] dilbert_feed
Dilbert readers - Please visit Dilbert.com to read this feature. Due to changes with our feeds, we are now making this RSS feed a link to Dilbert.com.
[syndicated profile] rebol_questions_feed

Posted by rnso

I am trying to print out text from all GUI elements in following code:

  sentlist: ["A" "B" "C"]

  main: function [slist] [
      view collect [
          repeat i length? slist [
              keep compose [
                  text (slist/:i)
                  field "" 
                  return
              ]
          ]
          keep [button "Printall" [
              repeat i (2 * length? slist)[
                  print face/parent/pane/(i)/text
              ]
          ]
       ]
    ]
 ]

 (main sentlist) 

It runs all right without any error and text elements' text are properly printed out, but for fields, only last field's entry is printed out for each field. Where is the problem and how can it be corrected? Thanks for your help.

Portrait

Sep. 18th, 2017 02:47 pm
[syndicated profile] forgotten_bookmarks_feed



Small tintype photograph.

Found in "Twenty Minutes Late" by Pansy. Published by Lothrop, 1893.

-Click to enlarge photos-
[syndicated profile] rebol_questions_feed

Posted by rnso

I am trying to create a panel with dynamically created gui elements:

  sentlist: ["A" "B" "C"]
  main: function [slist] [
    view collect [
      keep [below]
      repeat i length? slist [
        keep[
            text slist/i    ; THIS STEP IS NOT WORKING
            field "" ]
      ] ] ]

  (main sentlist) 

A series of strings is sent to the function for putting text labels from it. The GUI window/panel is opening all right but text elements do not have any label on it. Where is the problem and how can it be solved? Thanks for your help.

[syndicated profile] rebol_questions_feed

Posted by rnso

I am using following code to find products of 2 series of numbers and then to find sum of these products:

  make-row: func [][
    compose [
        t1: text "N1:"
        f1: field 
        t2: text "N2: "
        f2: field
        t3: text "Product: "
        t4: text ""
        b: button "Get product" [
            x: face/extra/2/text          
            y: face/extra/4/text
            z: (to-integer x) * (to-integer y)
            face/extra/6/text: rejoin [z]]
        do [b/extra: reduce [t1 f1 t2 f2 t3 t4]] ]  ]

  view compose [
        (make-row) return 
        (make-row) return
    b: button "Calculate" [t2/text: "..to be given"]
    t1: text "Sum of products:"
    t2: text ""                       ; NEED TO GET SUM OF ALL PRODUCTS IN ABOVE ROWS. 
  ]  

The first part is working all right - The products are being calculated properly. But how can I access these individual products to find sum of products? I could not find any way since the rows are not really objects whose public variables or methods/functions I may be able to access. How can this be solved? Thanks for your help.

Comic for September 18, 2017

Sep. 18th, 2017 11:59 pm
[syndicated profile] dilbert_feed
Dilbert readers - Please visit Dilbert.com to read this feature. Due to changes with our feeds, we are now making this RSS feed a link to Dilbert.com.
[syndicated profile] rebol_questions_feed

Posted by user310291

I want to get

[["1" "a"] ["2" "b"]] 

from

["1" "" "a" "2" "" "b"]

What's the right and most elegant way? I tried this but it doesn't get the result I want:

block: ["1" "" "a" "2" "" "b"]

new-block: []
sub-block: []

foreach [first second third] block [
  sub-block: []
  append sub-block first
  append sub-block third
  append new-block sub-block
] 
[syndicated profile] rebol_questions_feed

Posted by rnso

I am using following code to try to get GUI elements from a function:

  mypanelfn: func[] [
    collect[
      repeat i 10 [ 
        print append copy "i in loop: " i
        keep [t: text]  keep append copy "message: " i
        keep [field "entry"    
              button "Click" [t/text: "clicked"] return]]]]

  view [ 
    do [mypanelfn]]

There are no error messages and loop go on all right and a windows is also displayed. But this is only a small empty windows without any text, fields or buttons.

What is wrong with this code?

Edit: putting probe before collect shows (I have added line breaks for clarity):

[t: text "message: 1" field "entry" button "Click" [t/text: "clicked"] return 
t: text "message: 2" field "entry" button "Click" [t/text: "clicked"] return 
t: text "message: 3" field "entry" button "Click" [t/text: "clicked"] return 
t: text "message: 4" field "entry" button "Click" [t/text: "clicked"] return 
t: text "message: 5" field "entry" button "Click" [t/text: "clicked"] return

Comic for September 17, 2017

Sep. 17th, 2017 11:59 pm
[syndicated profile] dilbert_feed
Dilbert readers - Please visit Dilbert.com to read this feature. Due to changes with our feeds, we are now making this RSS feed a link to Dilbert.com.
[syndicated profile] rebol_questions_feed

Posted by rnso

I am using following code to add multiple GUI elements to a view via a foreach loop:

myRange: function [n][  ; to produce a vector of [1 2 3 4... n]
  vv: make vector! n 
  i: 1
  foreach j vv [
    vv/:i: i
    i: i + 1
    if i > n [break]]
  vv ]

view collect[ 
    foreach i myRange 10 [  
        print append "i in loop: " i
        keep [ t: text ]  keep append "message number: " i
        keep [field "entry"     button "Click" [t/text: "clicked"] return]
            ] ]

All GUI elements are being produced. But the code append "message number: " i is showing value of i to be 12345678910 in all text elements and not 1, 2, 3... 10 for different text elements.

Also, print append... statement is producing following output:

i in loop: 1
i in loop: 12
i in loop: 123
i in loop: 1234
i in loop: 12345
i in loop: 123456
i in loop: 1234567
i in loop: 12345678
i in loop: 123456789
i in loop: 12345678910

Moreover, clicking any button changes text of only the last added text element.

Where is the problem and how can it be solved? Thanks for your help.

Saving data to file in Red language

Sep. 16th, 2017 03:54 pm
[syndicated profile] rebol_questions_feed

Posted by rnso

I am trying to save data to a file:

a: 0
b: 10
c: 20
d: 30

save %redout.txt [a b c d]

I expected the file to contain the values. However, The file contains:

a b c d

How can I save variable values rather than variable names to the file?

Giveaway winner

Sep. 16th, 2017 02:42 pm
[syndicated profile] forgotten_bookmarks_feed
This week's winner was Maria Linder Vance, who entered on Facebook.

Thanks to all who entered, see you here next week.

Comic for September 16, 2017

Sep. 16th, 2017 11:59 pm
[syndicated profile] dilbert_feed
Dilbert readers - Please visit Dilbert.com to read this feature. Due to changes with our feeds, we are now making this RSS feed a link to Dilbert.com.

Making GUI objects in Red language

Sep. 16th, 2017 04:47 am
[syndicated profile] rebol_questions_feed

Posted by rnso

I have following simple code for a small panel:

view [
    t: text "label"
    f: field
    button "Click here" [t/text: f/text]    ]

But I have to make 2 of them and put them on one window. I want to create single object class and make 2 objects out of it. I see that objects can be created as follows:

obj: object [
    view [
        t: text "label"
        f: field
        button "Click here" [t/text: f/text] ]  ]

view [
    obj
    obj     ]

But I get following error:

*** Script Error: VID - invalid syntax at: [obj obj]
*** Where: do
*** Stack: view layout cause-error 

How can this be done? Thanks for your help.

Edit: I tried with do but could manage only with does:

  myview: object [
      show: does [view[
        below
        t: text "1st time"
        f: field "Enter value"
        button "Click here" [f/text "clicked"]
        area] ] ]

  myview/show

  print "READY TO SHOW 2nd OBJECT: "
  myview2: copy myview
  myview2/show
[syndicated profile] rebol_questions_feed

Posted by rnso

I have 2 lists:

alist: [a b c d]
blist: [1 2 3 4]

(In reality they are long lists). How can I assign variables in alist to corresponding values in blist in one go? Hence a becomes 1, b becomes 2 and so on.

I tried:

foreach i alist j blist [i: j]

But it give following error:

*** Script Error: j has no value
*** Where: foreach
*** Stack: 

I also tried:

i: 1
while [true] [ 
    if i > (length? alist) [break]
    alist/i: blist/i  
    i: i + 1
]

But it also does not work:

*** Script Error: cannot set none in path alist/i:
*** Where: set-path
*** Stack: 

alist/i and blist/i return none (on checking with print command).

Similar question are there for other languages also, e.g.: Parallel array assignment in PHP and Parallel assignment in Java? . Thanks for your help.

Comic for September 15, 2017

Sep. 15th, 2017 11:59 pm
[syndicated profile] dilbert_feed
Dilbert readers - Please visit Dilbert.com to read this feature. Due to changes with our feeds, we are now making this RSS feed a link to Dilbert.com.

Try/catch exceptions in Red language

Sep. 15th, 2017 03:23 am
[syndicated profile] rebol_questions_feed

Posted by rnso

I have a small GUI application with a text-field and a button. The button triggers a function which tries to read a number from text-field. An exception is raised if the text-field is blank or has non-numeric text.

I am trying to catch error if text-field does not have a value or has text value rather than a valid number:

calc: does [
    try [x: to integer! num_field/text]
    catch [ print "Could not get number"]
    print "Number read"
]

Following also does not work:

calc: does [
    try [x: to integer! num_field/text]
    throw 123
    print "Number read"
]
catch 123 [ print "Could not get number"]

I am not sure how to use try, throw and catch here. I tried to check section 10 of http://static.red-lang.org/red-system-specs.html but could not really understand.

How can this be solved? Thanks for your help.

[syndicated profile] rebol_questions_feed

Posted by rnso

I compiled an executable using following simple code (from Red language websites) in Red language:

Red [title: "test" needs: 'view]
view [
    below
    button
    field
    text "Red is really pretty easy to program."
    text-list
    check
]

I used following command:

red -c myprog.red

It was created without any error. However, when I run it there are 2 problems:

  1. The application window does not have the title given above ("test").

  2. A console window also opens that closes only after the application is shut down. It will be better if such a window does not open at all and only application window opens.

I am working on Windows-7. Where is the problem and how can these be solved? Thanks for your help.

Creating pdf file in Rebol/Red

Sep. 14th, 2017 08:09 am
[syndicated profile] rebol_questions_feed

Posted by rnso

I need to create a pdf file of A4 sized page which will have a black and white image and some text. Can I create a pdf file in Rebol or Red programming language?

If not possible directly, what is the best way to do it- create an image file which can be printed by external programs? Thanks for your help.

Comic for September 14, 2017

Sep. 14th, 2017 11:59 pm
[syndicated profile] dilbert_feed
Dilbert readers - Please visit Dilbert.com to read this feature. Due to changes with our feeds, we are now making this RSS feed a link to Dilbert.com.
[syndicated profile] rebol_questions_feed

Posted by rnso

I am trying following code where user enters 2 numbers and on clicking calculate button, answer should be shown. There are also buttons for clearing fields and for exiting.

REBOL[]

fields: [f-ht f-wt ans]
reset-fields: does [
    unfocus
    f-ht/text: " "   ; Changing this to "ENTER NUMBER HERE" does not help
    f-wt/text: " "
    focus f-ht
]

oncalc: does [ 
    ans/text: (to integer! f-wt/text) / ((100 * to integer! f-ht/text) * (100 * to integer! f-ht/text))
    show fields
]

lo: layout [
    style tx label 200x24 center
    style fld field 200x24 center
    style btn button 200x24 center

    tx "First Number:" 
    f-ht: fld 
    tx "Second Number:" 
    f-wt: fld 
    btn "Calculate" [oncalc]                   
    ans: tx "Answer"
    btn "Clear" [reset-fields show fields]     ; NOT WORKING- NOTHING HAPPENS
    btn "Exit" escape [unview/only lo]
]
reset-fields
view center-face lo

The GUI is showing all right. However, there are following problems:

On clear button clicking, nothing is happening.

There are no changes on GUI and no errors are being reported. Where is the problem and how can this be solved? Thanks for your help.

Compile Rebol code to executable

Sep. 14th, 2017 03:51 am
[syndicated profile] rebol_questions_feed

Posted by rnso

I downloaded Rebol/View (vesion 2.7.8) Linux x86 libc6 2.3 version from http://www.rebol.com/downloads.html and it is working all right as an interpreter on Linux (Debian Stable 9). Is it possible to compile the code to executables? I tried checking the options, and compile to executable option does not seem to be there:

$ rebol -v --help
The command line usage is:

    REBOL <options> <script> <arguments>

All fields are optional. Supported options are:

    --cgi (-c)       Check for CGI input
    --do expr        Evaluate expression
    --link url       Connect to Link
    --help (-?)      Display this usage information
    --nowindow (-w)  Do not open a window
    --noinstall (-i) Do not install (Link, View)
    --quiet (-q)     Don't print banners
    --reinstall (+i) Force an install (Link, View)
    --script file    Explicitly specify script
    --secure level   Set security: allow ask throw quit
    --trace (-t)     Enable trace mode
    --uninstall (-u) Uninstall REBOL (Link, View)
    --version tuple  Minimum version of script, when URL (View)
    --noviewtop (-v) Do not start viewtop (view desktop)

Special command line options:

    +q               Force not quiet (Link, View)
    -s               No security
    +s               Full security
    -- args          Provide args without a script

Examples:

    REBOL script.r
    REBOL -s script.r
    REBOL script.r 10:30 test@domain.dom
    REBOL --do "verbose: true" script.r
    REBOL -cswq
    REBOL --cgi --secure throw --script cgi.r "debug: true"
    REBOL --version 1.2.3 http://www.rebol.net/test.r ; view only

Can I compile Rebol code to executable code on Linux/Windows? Thanks for your help.

Garbage collection in Rebol & Red

Sep. 13th, 2017 06:01 pm
[syndicated profile] rebol_questions_feed

Posted by rnso

Rebol and Red seem to be new programming languages with some interesting features. IMHO, safety should be a high priority of all languages. Do these 2 languages have automatic or manual methods for garbage collection or memory management to avoid system crashes? If so, what are the methods that can be called manually to clear up memory problems? Thanks for your help.

Profile

birguslatro: Birgus Latro III icon (Default)
birguslatro

August 2017

S M T W T F S
  1 2345
6789 101112
13141516171819
20212223242526
2728293031  

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags