AltME: Rebol School

Messages

amacleod
What's the best way to search a block of blocks for specific values. Is there a more efficient way other then looping through each block?
would key-value scheme make it easier?
Bo
amacleod: We just were discussing that in the !REBOL3 group.
amacleod
k, thanks

Sunanda
Gregg suggests this is a good group to post puzzles.....Actually, it is a real situation for which I wrote some grossly inelegant code. My code works, but it hardly shows off the beauty of Rebol or the power of Parse. So looking to see if anyone can do better than my 15 or so lines of procedural code....
I have a block that consists of string!s and blocks!s -- think of it as a set of parameters: a keyword string is usually followed by a [set of options], eg:
   parameters: ["keyword1" [char 20] "keyword2" [num max 999] "keyword3" [] "keyword1" [not null] ]
There can be blocks without keywords and keywords without blocks -- and keywords can be duplicated as above with "keyword1".
What I need is a normalization routine to insert empty strings or blocks such that every string is followed by a block and every block is preceded by a string Example:
    In:  [   [upper]   "key 1"      "key-2" [no]      [off]   "key 1"    ]
    Out: ["" [upper]   "key 1" []   "key-2" [no]   "" [off]   "key 1" [] ]
You can assume that there are only strings and blocks in the input -- or for bonus points, come up with something cleverer than my code (an initial REMOVE-EACH loop to quietly throw away non-conforming datatypes).
Thanks!
sqlab
How about
>> out: collect [
[    parse In [ some [
[            [copy str string! copy bl block!  (keep  str keep bl)]
[            | [copy str string! (keep  str keep copy []) ]
[            | [copy bl block! (keep  copy "" keep bl) ]
[            | skip
[            ] ]
[    ]
== ["" [upper] "key 1" "key-2" [no] "" [off] "key 1"]
>  ?
Sorry that was wrong (:
sqlab
keep/only does the trick
out: collect [
    parse In [ some [
        [copy str string! copy bl block!  (keep  str keep  bl)]
        | [copy str string! (keep  str keep/only  []) ]
        | [copy bl block! (keep   "" keep bl) ]
        |  skip
    ]   ]
]
== ["" [upper] "key 1" [] "key-2" [no] "" [off] "key 1" []]
Sunanda
That looks good, sqlab -- thanks!
One minor change:   keep/only  []   ===> keep/only  COPY []
Then each inserted empty block is a different one (which wasn't explicitly stated in the puzzle description; but it helps the actual app).
Ditto (keep COPY "" keep bl)
Endo
I constantly forget about COLLECT and KEEP, and everytime I say "cool!" when I see them :)

CelesteM
This might not be the best place to ask this but since it directly involves learning it seems as good a place as any. I'm wondering what books any of you might deem essential for programming and systems architecture. Do any of you have a favorite book on system architecture?
Gregg
On Software Architecture
- Beautiful Atchitecture is real world stories, but not all will teach you something. Overall I like it.
- Software Architecture in Practice is dry and rigid. I don't like it.
- Software Architecture and Design (Witt, Baker) is pretty good, if somewhat dated
- Software Architecture (perspectives on an emerging discipline) (Shaw, Garlan) I like, as it's not huge and their views align with mine. :-)
- Beyond Software Architecture didn't grab me. Lots of business related stuff in it.
- Domain Driven Design is good, as it applies to DSLs and such.
On programming, are you looking for coding specific stuff (e.g. Programming Pearls, Code Complete) or more general (Making Software, Rapid Development)?
SWhite
CelesteM
I'm looking to improve the way I structure my code so that it's both more readable and easier to maintain.
Geomol
Books I often use in combination with programming/development/language design:
- The C Programming Language (Kernighan and Ritchie).
    Most out of need, as I program in C also. Wish I didn't have to.
- Object-oriented Software Construction (Bertrand Meyer)
    Many very good ideas, even for outside real object-oriented languages.
- Programming Languages: Design and Implementation (Terrence W. Pratt)
    Cover lots of languages and designs.
- Data Structures and Algorithm Analysis (Mark Allen Weiss)
    The data structures ABC.
- Amiga ROM Kernel Reference Manual, Libraries & Devices
    Yeah, it actually still has useful stuff, even if it is old.
Carl's Style Guide has good tips for readability:
http://www.rebol.com/docs/core23/rebolcore-5.html#section-5
I changed my way of writing code, after I looked at the sources for Lua. Now I tend to write condenced code without empty lines, and then have two empty lines between functions.
And putting brackets on the same line as function definition, and space before parenthesis:
    void my_function (arg1, arg2) {
        ...
    }
Same with IF, WHILE, etc in REBOL:
    if something [
        do this
    ]
    while [this-is-true] [
        do this
    ]
CelesteM
That's how I format my code as well but I'm looking for something more along the lines of naming convention dos and don'ts. And how to create useful objects in OO programming.
Geomol
On naming, Carl has the best suggestions, as I see it:
5.2 Word Names
5.2.1 Use the Shortest Word that Communicates the Meaning
5.2.2 Use Whole Words Where Possible
5.2.3 Hyphenate Multiple Word Names
5.2.4 Begin Function Names with a Verb
5.2.5 Begin Data Words with Nouns
5.2.6 Use Standard Names

Last message posted 184 weeks ago.