Open ldci opened 3 months ago
Why you don't use the block directly? You should not copy values one by one as you do in your code. It is better to use something like:
block2Vector: function[type [word!] block [block!]][
make vector! compose/only select make map! [
int8 [integer! 8 (block)]
int16 [integer! 16 (block)]
int32 [integer! 32 (block)]
int64 [integer! 64 (block)]
uint8 [unsigned integer! 8 (block)]
uint16 [unsigned integer! 16 (block)]
uint32 [unsigned integer! 32 (block)]
uint64 [unsigned integer! 64 (block)]
float32 [decimal! 32 (block)]
float64 [decimal! 64 (block)]
] type
]
Then:
>> b: [#"A" #"B" #"a" #"b"]
== [#"A" #"B" #"a" #"b"]
>> block2vector 'float32 b
== make vector! [decimal! 32 4 [65.0 66.0 97.0 98.0]]
>> block2vector 'uint8 b
== make vector! [unsigned integer! 8 4 [65 66 97 98]]
Maybe the make vector dialect could be smarter and accept the types as used in the construction syntax already. And resolve the data from a variable without need to use compose/only
..
This could be implemented:
make vector! [uint16! :data]
Which would be same like:
make vector! compose/only [unsigned integer! 16 (data)]
Elegant :) [image001.png][image002.png]
François Jouen https://univ-psl.fr/ École Pratique des Hautes Études Doyen Honoraire de la section des Sciences de la Vie et de la Terre Chaire de Psychobiologie du Développement Plateforme Réanimation Pédiatrique Raymond Poincaré. Hôpital de Garches Laboratoire Cognitions Humaine et Artificielle Campus Condorcet 14 cours des Humanités 15 rue Waldeck Rochet 93322 Aubervilliers cedex 06 87 13 76 81 @.**@.> www.ephe.frhttp://www.ephe.fr/
Le 16 août 2024 à 13:47, Oldes Huhuman @.***> a écrit :
Why you don't use the block directly? You should not copy values one by one as you do in your code. It is better to use something like:
block2Vector: function[type [word!] block [block!]][ make vector! compose/only select make map! [ int8 [integer! 8 (block)] int16 [integer! 16 (block)] int32 [integer! 32 (block)] int64 [integer! 64 (block)] uint8 [unsigned integer! 8 (block)] uint16 [unsigned integer! 16 (block)] uint32 [unsigned integer! 32 (block)] uint64 [unsigned integer! 64 (block)] float32 [decimal! 32 (block)] float64 [decimal! 64 (block)] ] type ]
Then:
b: [#"A" #"B" #"a" #"b"] == [#"A" #"B" #"a" #"b"]
block2vector 'float32 b == make vector! [decimal! 32 4 [65.0 66.0 97.0 98.0]]
block2vector 'uint8 b == make vector! [unsigned integer! 8 4 [65 66 97 98]]
— Reply to this email directly, view it on GitHubhttps://github.com/Oldes/Rebol-issues/issues/2616#issuecomment-2293359930, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAXI3IODYVIGVRCEFKCQAA3ZRXREFAVCNFSM6AAAAABMR24CGWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTGM2TSOJTGA. You are receiving this because you authored the thread.Message ID: @.***>
With R3 it's easy to use blocks when creating vectors when blocks are internal.
Now the question is how to use external blocks? In this case R3 returns an error. We have the possibility with such as function:
And for test, some examples: