On 7/24/2016 2:42 PM,
franck....@gmail.com wrote:
> Le dimanche 24 juillet 2016 19:44:32 UTC+2, Cecil - k5nwa a écrit :
>> I did not go through quite all the tutorials, after a little bit I tried
>> to make a simple tutorial of my own to test some concepts in simple
>> string and list conversions and didn't get anywhere as some of the words
>> I "think" I would need were not documented so the only choice I had was
>> to pour through the source code to figure it all out, and since the
>> software right now is in the state of flux I figure if I had to go
>> through that effort I will wait a while until things settle down. I'm
>> thinking that V1.0 will bring additional changes ,so now it's better to
>> wait a bit and see what happens.
>>
>>
>> I have tried several offshoots of Forth so that things are getting a
>> little mixed up as to what software has what features. So maybe I need
>> to repeat the process, and document the findings so I don't forget where
>> all the various versions of Forth stand. One thing I do want to have are
>> mutable list items, which from reading Oforth does not have that but I
>> could be mistaken so I will wait until the new version comes out.
>>
>>
>> --
>> Cecil - k5nwa
>
> Even if immutability is a key concept in Oforth, mutable list exist
> (and are sometimes more suitable than immutable objects).
Good to hear, I vaguely remembered that there was a way to get list of
items and be mutable, so maybe my documenting this information is needed
to avoid getting the different Forth systems that I been looking at
mixed up.
>
> They are instances of ListBuffer class.
> (and mutable strings are instances of StringBuffer).
>
> You can find a reference of all words defined at startup
> (including ListBuffer methods) here :
http://www.oforth.com/lang.html
>
Unfortunately for me, that list rarely list what the expected parameters
are. Also some basic items are not defined, for example what is a
"receiver" in some cases I gather that it is the top of the stack, but
in some items I'm not sure.
> I doubt that those words will change a lot with V1.0
>
> Basically, you can create a new list using :
> ListBuffer new
> or
> n ListBuffer newSize
>
> If you know what will be the list size, it is better to use #newSize to
> avoid the list to be resized for nothing.
>
> Then you can add new elements using #add method :
> aListBuffer add ( x -- )
>
> or update elements using #put :
> aListBuffer put ( i y -- )
I will not know how big a list is until the code is actually reading the
input text, so I planned to declare the "ListBuffer" at a reasonable
size and then grow as needed, in most cases it will not need to grow.
The one ListBuffer will keep getting reused so as it grows the chances
of it needing to grow will diminish.
My plan is to parse a set of code into the list, then proceed to process
it looking for patterns and doing substitution of the text. If
processing Forth as an example, I would load an entire word definition
into the list array and process it as a whole entity, it may not be the
best way but it's a way I have done before and worked well.
The goal would be to use templates to optimize the word definition and
then generate optimized assembler code to be compiled as the final result.
In the past I used a similar method to translate languages, and to
optimize the Forth code and generate code for various CPU chips. The
process would first optimize the forth code to an internal form using
special optimized micro ( quarks ) primitives that translate well to
assembler then those optimized primitives would be translated to
assembler code for the specific CPU. Not only did it generate decent
code but I was able to easily modify it to work with several CPUs. The
thing is one can start simple with few templates but as one adds more
templates the code generated keeps improving.
>
> The list will automatically be resized if necessary.
>
>
> For instance, this is how #zipWith is implemented, using a ListBuffer :
>
> Indexable method: zipWith( coll r -- aList )
> | i |
> self size coll size min dup ListBuffer newSize swap
> loop: i [ i coll at i self at r perform over add ]
> dup freeze ;
>
> [ 1 , 2 , 3 ] #[ + 1+ ] [ 4 , 5 , 6 ] zipWith .
> [6, 8, 10] ok
>
>
> Franck
>
--
Cecil - k5nwa