• Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r4wp

[#Red] Red language group

Arnold
17-Jun-2013
[8484]
Unsined integers is on the wish-list for Red/System v2 https://github.com/dockimbel/Red/wiki/Red-System-v2-Wish-List
point 29
DocKimbel
17-Jun-2013
[8485x3]
You can always have an unsigned integer using a simple pointer.
Also, "unsigned" is just a convention, the data is same as the signed 
version.
As Kaj said, you can achieve the same calculation with signed integers, 
you just need to be careful.
Maxim
17-Jun-2013
[8488x2]
one question for Red/System.  


can it already, ( or is it planned ) to export static libs for use 
within (C/C++, other?) compiler/linkers?
this would be an nice way for users to try red and progressively 
replace their binary code base, one source file at a time... instead 
of a whole project at once.
Kaj
17-Jun-2013
[8490]
Yes, not yet, but it's in the roadmap. Currently, you can replace 
a project one shared library at a time, or one 0MQ service at a time
DocKimbel
18-Jun-2013
[8491x3]
I have a new test pre-release version for Android, could some of 
you test it on different devices?

http://static.red-lang.org/hello2.apk
It should display an input field and a "Do" button, allowing you 
to evaluate arbitrary Red code. The result of evaluation scrolls 
up, below the button.
On Nexus4, it doesn't run. I would like to see how it reacts on other 
4.x devices and also older ones. It runs fine on my HTC 2.3.5.
Bo
18-Jun-2013
[8494]
On my Motorola XT881 running 4.1.2, Red opens and then immediately 
closes again.
DocKimbel
18-Jun-2013
[8495]
Thanks Bo. Anyone with a 4.0.x device?
XieQ
18-Jun-2013
[8496x2]
It runs fine on my Motorola ME525+ 2.3.6, but can't use PRINT, is 
that OK?
And on my ONDA Pad 4.1.1, it's opens and then immediately closes 
again.
DocKimbel
18-Jun-2013
[8498x3]
The printing is redirected to the logcat. To see it, you need a logcat 
viewer like eLogcat from PlayStore.
I just remembered that I bought a few months ago a cheap Android 
4.1 USB stick, I will look at the 4.x issues tomorrow.
When we'll have a true Red console emulation for Android, we'll be 
able to redirect the printing functions back to the console.
AdrianS
18-Jun-2013
[8501]
The .apk wouldn't install on my Galaxy Nexus with 4.2.2.
GrahamC
18-Jun-2013
[8502]
Curious it installed on my N7
Pekr
18-Jun-2013
[8503x2]
runs on my htc sensation 4.0.1
the only strange thing - the evaluator, when I mistakenly put: 1 
+ t = 1
DocKimbel
19-Jun-2013
[8505]
Ah, so it's HTC-friendly it seems. :-)
Arnold
19-Jun-2013
[8506]
t=0
Pekr
19-Jun-2013
[8507]
I did not define 't, expected error being raised ...
Arnold
19-Jun-2013
[8508]
so, it solved the equation! Pretty smart thing.
DocKimbel
19-Jun-2013
[8509]
Actually, you got an error message sent to your logcat. :-) Once 
things will be stabilized for 4.x support, I'll redirect printing 
to the GUI.
Endo
19-Jun-2013
[8510]
It works on Samsung S3 Galaxy, Android 2.3.6
DocKimbel
19-Jun-2013
[8511]
I've reproduced the 4.x issue on my Rikomagic USB stick.
Arnold
19-Jun-2013
[8512]
Login on SO requires a OpenID account. Don't want to link all my 
info on the web. SO is over for me.
Pekr
19-Jun-2013
[8513]
I don't have OpenID, yet I am using SO, is it really a necessity?
Maxim
19-Jun-2013
[8514]
AFAIK you can create an account just for SO
Arnold
19-Jun-2013
[8515x2]
I have an account on Wordpress.com lying around, even can login to 
Wpress, but SO says "You don't own that identity" :(
creating a separate account
Arnold
20-Jun-2013
[8517]
The deobfuscating Knuth's random program project is progressing into 
its final stage. It turned out that with getting the results of the 
program the same only the first part of the puzzle got solved. To 
use it in real programs you use the provided ran_arr_next function. 
This involved some pointer aritmetic that is not 100%  supported 
by Red/System. I finally got the function to produce the same results 
as the C version. The downside is it is now quite a mess with pointer 
indeces and other variables, so a lot of cleaning up to do and/or 
rework only using the index on the array approach.
DocKimbel
20-Jun-2013
[8518]
This involved some pointer aritmetic that is not 100%  supported 
by Red/System.
 What is it lacking precisely?
Arnold
20-Jun-2013
[8519]
It is just slightly different. The possibility to go back to the 
first element of the array or store that address. :(ran_arr_buf/1) 
would make it a lot easier. 

I already had a lot of help from Peter on this (thumbs up!) and I 
made good progress by now.

I get the pointer of the array and I can go up and down  using + 
and -, this works great, and the pointer is going along with it then 
and I suspect that if I do 
ptr: ran_arr_buf 
and I progress ran_arr_buf by 1 that I progress ptr too.

I now kinda solved it by using an additional variable. When I reach 
a 100, I subtract 100 from the array ran_array_buf to go back. 

Tonight and tomorrow I have some time to clean up my code and I can 
experiment some more. 

It is proven it can be done, but keeping the extra variable is surely 
slowing down compared to C's pure pointer solution.
DocKimbel
20-Jun-2013
[8520]
I suspect that if I do 
    ptr: ran_arr_buf 
and I progress ran_arr_buf 
by 1 that I progress ptr too.


That's a wrong assumption. Those two variables are distincts, so 
each one has its own memory slot. If you change one, that has no 
effect on the other. What is shared there is the pointed memory region. 
So, if you change ran_arr_buf/value, that will affect ptr/value (they 
both point to the same memory location).
Arnold
20-Jun-2013
[8521x3]
my trouble seems to arise from the different roles the array and 
the pointer play in the C code vs the Red/System code. In C the pointer 
is used as indicator for initialisation and signals when a kind of 
reshuffle is required and it points to the next generated value. 
In Red/System the array points to the current/next value and a pointer 
is not needed, and you can no longer use it as before to signal the 
status. This complicates things in this case.
Oh nice effect. array1: 1 2 3 4 5 
m: 2
;;print array/m ;; 2
array1: array1 + 2
;;print array/m ;; 5

it is tricky to move the array pointer around, beware of the dog 
;)
sorry 5 has to be 4 in that example.
DocKimbel
20-Jun-2013
[8524x2]
You seem quite confused about pointers in Red/System. 


1) There's no "array" as distinct entity in Red/System, but you have 
indexed access, so you can "simulate" arrays to some extent.


2) "In C the pointer is used as indicator for initialisation and 
signals when a kind of reshuffle is required and it points to the 
next generated value." I don't understand this sentence, you should 
stick to C terminology (terms like "signals", "reshuffle" and "generated 
value" are alien to me in a C language context).


3) "In Red/System the array points to the current/next value and 
a pointer is not needed, and you can no longer use it as before to 
signal the status." I don't understand this one either... There's 
no array, only pointers. "to signal the status" has no meaning to 
me...sorry.
I think you have a complicated mental representation of what pointers 
and arrays are in C and Red/System. It's simpler and more straightforward 
than your descriptions. Basically, Red/System pointers act the same 
way as C ones (including "array" support). The only difference is 
the base for indexed accesses (1 vs 0).
Kaj
20-Jun-2013
[8526x4]
Arnold, what you call :(ran_arr_buf/1) is possible and is just
:ran_arr_buf
Sorry, even simpler:
ran_arr_buf
Arnold
20-Jun-2013
[8530]
Yes I know, I built one in already, except when you have shifted 
the ran_arr_buf, this one shifts along, but I want to return then. 
So I saved it in a sav_arr_buf to take care of this. All in all because 
I try to stay as close as possible to the original I have some extra 
bookkeeping to take care of. Later today I will clean up the code 
further and hope the smoke clears up ;)
XieQ
21-Jun-2013
[8531]
@Arnold I write the Mersenne Twister random function in Red/System 
according to an educational C standard library implementation ( http://code.google.com/p/c-standard-library/source/browse/src/internal/_rand.c
). Hope you find it useful. you can read it from here: https://gist.github.com/qtxie/5831308
DocKimbel
21-Jun-2013
[8532]
Great work XieQ, congrats! Have you checked it against a C version 
to verify that the output is the same, given the same seed number?
Kaj
21-Jun-2013
[8533]
Looks good