World: r3wp
[Core] Discuss core issues
older newer | first last |
Anton 10-Jan-2005 [81] | yeah, just pre-scan... if the cost is not too high. Is the record access slow ? |
Pekr 10-Jan-2005 [82] | no, I think not .... I am waiting for RIF anyway ... |
Sunanda 10-Jan-2005 [83] | Anton -- I had to debug the problems with Sort/all/skip/compare -- code that worked on one platform, but failed on another. It got burned into the brain. |
Pekr 10-Jan-2005 [84] | In Silesion group, late today I will post about what I have in plan and will "complain" a bit about IOS ... it is so primitive db vise, that it is not much usable ... |
Sunanda 10-Jan-2005 [85] | Petr, for fault tolerance, something like: sort/compare ...... func [a b] [ attempt [return a/x < b/x] return false] |
Pekr 10-Jan-2005 [86x7] | excelent - it does not return error, block is sorted, now I have to find out, what it did with record, which is missing field agains which I did compare .... |
why is there "return false"? | |
hmm, that return false seems to change search results ... | |
Can you follow following test case, please?: | |
>> blk: [[name "pekr" test [cz "bbb"]] [name "adriana" test [cz "aaa"]] [name "beatrice" test [cz ""]]] == [[name "pekr" test [cz "bbb"]] [name "adriana" test [cz "aaa"]] [name "beatrice" test [cz ""]]] >> sort/compare blk func [a b][attempt [a/test/cz < b/test/cz] return false] == [[name "adriana" test [cz "aaa"]] [name "beatrice" test [cz ""]] [name "pekr" test [cz "bbb"]]] >> sort/compare blk func [a b][attempt [a/test/cz < b/test/cz]] == [[name "beatrice" test [cz ""]] [name "adriana" test [cz "aaa"]] [name "pekr" test [cz "bbb"]]] >> | |
Let's say I will pre-scan records and fill-in empty string in the case of missing field .... | |
you can see results of two sort calls, first one using return false, second one did not. The second one is sorted properly ... so I think that once attempt is called, it does something to sort ... | |
Sunanda 10-Jan-2005 [93] | Why return false? It was a very quick attempt to ensure that the sort always returns true or false. But which (as you say) depends on whether a/x or b/x is missing. Maybe better is func [a b] [ attempt [return a/x < b/x] ;; both exist attempt [a/x return true] ;; only a/x exists attempt [b/x return false] ;; only b/x exists return false] ;; neither exist It''d be a lot faster (I guess) if you refactor to remove the attempt blocks -- use value? |
Pekr 10-Jan-2005 [94] | I just wonder what does it do to sort itself, once it finds record is missing the field? will it let the record untouched on the same position? Can't it affect following sort operations? |
Sunanda 10-Jan-2005 [95] | I think the sort/compare only does what you tell it to do in terms of the comparisons. |
Tomc 10-Jan-2005 [96x2] | Pekr: As Sunanda mentioned return -1,0,1 for a stable sort. if you want to leave a record untouched when a key field is missing then return zero otherwise return 1, or -1 |
func [a b] [attempt [return a/x < b/x] ;; both exist return 0 ;; nothing can be said because at least one does not exist so they are equilivant ] | |
Pekr 10-Jan-2005 [98x3] | and -1 means what? |
I would like it to behave as follows - in DB world, there are mostly string fields, and if you have "" (empty string = value is not set), you want to have it listed in the beginning of the grid-style ... | |
so, none, or nonexistant field should sort as if it is of lowes value .... | |
Tomc 10-Jan-2005 [101] | a > b -> 1 a = b -> 0 a < b -> -1 |
Pekr 10-Jan-2005 [102x2] | so return false was not enough :-) |
may I switch on logical values? switch true [true "print true"] ... does not work ... | |
Tomc 10-Jan-2005 [104] | with only two states for logic 'either makes more sense |
Pekr 10-Jan-2005 [105x2] | your above function will not work imo ... |
there can be several states - non existant 'a, non existant 'b, both not existant, a < b, a = b, a > b :-) | |
Tomc 10-Jan-2005 [107] | in your case you seem to want null have a value that sorts before any known value which is fine for you. but in general, the three cases where a b or both are null are equalivanrt in that no comparison can be made and so are "vacuously true" because they cannot be proved false. |
Vincent 10-Jan-2005 [108] | Pekr: switch true reduce [true "print true"] does work. 'true in your block is the word 'true, not the value true. |
Gabriele 11-Jan-2005 [109] | ...or switch true [#[true] [print "true"]] |
Pekr 11-Jan-2005 [110] | what version of Core will that work from? Will it work in IOS? |
Anton 11-Jan-2005 [111] | From at least View 1.2.5.3.1 it works. (not sure about Core) |
Vincent 11-Jan-2005 [112] | #[true] works from /Core 2.5.1 (but not in 2.5.0) |
Sunanda 12-Jan-2005 [113] | It's easy to do case sensitive or case insensitive tests for equality: >> "abc" = "ABC" == true >> "abc" == "ABC" == false (Or use equal? and strict-equal?) Anyone know a similar shorthand way to do the same for greater/less than comparisons? >> "abc" < "ABC" == false >> "abc" > "ABC" == false Right now, I'm using to-binary to get the right result: >> (to-binary "abc") < (to-binary "ABC") == false >> (to-binary "abc") > (to-binary "ABC") == true |
Geomol 12-Jan-2005 [114x3] | No, there doesn't seem to be a strict-greater? action, but you can make such a function to get more readable code: strict-greater?: func [value1 value2] [(to-binary value1) > (to-binary value2)] Which makes me remember, that it's not possible to make new in-fix actions in REBOL!? |
Functions are pre-fix (name of function followed by arguments), actions are in-fix (argument1 action! argument2), and there are no post-fix words in REBOL. I'm not too familar with the language theory, REBOL is based on, but should it be possible to make new in-fix words? And what about post-fix? Or is that just too confusing? | |
(Well, arguments could be said to be post-fix words... hmm) | |
eFishAnt 12-Jan-2005 [117] | you can build your own parsing, and your own dialects as well...depending on your application |
Geomol 12-Jan-2005 [118] | True. I also actually meant op! types (operators), not action! And the operators in REBOL are pretty basic, so no need for new ones, I guess. |
Sunanda 13-Jan-2005 [119x2] | There's no way as fas a as I know of making new in-fix words. There should be -- the currrent ones work both ways, so the mechanism must be there somewhere: >> 6 < 5 == false >> < 6 5 == false |
Thanks for the strict-greater? idea. I was hoping there was a built-in ability somewhere. One tiny tweak to the function -- you need to restrict the two values to series or you can get strange results: >> strict-greater? make object! [1] make object! [0] == false >> greater? make object! [1] make object! [0] ** Script Error: Cannot use greater? on object! value So: strict-greater?: func [value1 [series!] value2 [series!]] [(to-binary value1) > (to- binary value2)] | |
Ladislav 13-Jan-2005 [121x2] | Infix words are "hard-wired" from the Rebol programmer POV currently |
postfix operators aren't reasonable to have, the prefix versus infix issues are complicated enough | |
Geomol 13-Jan-2005 [123] | The infix operators in REBOL can be seen with: >> ? op! It's a special corner of REBOL, as I see it. And I don't feel a big need to be able to make my own infix operators. There is a funny thing with the and, or and xor operators. They have twin and~, or~ and xor~ actions. The actions is used like: <action> <value1> <value2>, but operators can be used the same way, so the action counterparts seem to be irrelevant. Examples: >> 3 and 9 >> and 3 9 >> and~ 3 9 Why do we have and~, or~ and xor~ made? |
Anton 13-Jan-2005 [124] | I suspect that originally, the infix operators weren't also able to be used prefix. |
Vincent 13-Jan-2005 [125] | One can overload 'and~ 'xor~ 'or~ but should not overload 'and 'xor 'or. With form~ we know they are only used in <action> <value1> <value2>, and are safe to change. |
Ladislav 13-Jan-2005 [126] | I think, that it is an *unsafe* and confusing practice to use infix operators as prefix |
shadwolf 13-Jan-2005 [127x4] | I have one little thing to ask for my personal knowledge and I hope for people to thinks together on a good way to exploit it in REBOL to enhance it's capability to interface with DLL or exploit files containing memory struct dump: |
the thing is how to load or convert a C structure like this and use it in REBOL in a approachant way of C (I hope we could find even a better way to do it with rebol than in C) | |
//------------------------------------------------------------- //- SMD2Header //- Header for all Md2 files, struct SMD2Header { int m_iMagicNum; //Always IDP2 (844121161) int m_iVersion; //8 int m_iSkinWidthPx; int m_iSkinHeightPx; int m_iFrameSize; int m_iNumSkins; int m_iNumVertices; int m_iNumTexCoords; int m_iNumTriangles; int m_iNumGLCommands; int m_iNumFrames; int m_iOffsetSkins; int m_iOffsetTexCoords; int m_iOffsetTriangles; int m_iOffsetFrames; int m_iOffsetGlCommands; int m_iFileSize; }; //------------------------------------------------------------- //- SMD2Vert //- Vertex structure for MD2 struct SMD2Vert { float m_fVert[3]; unsigned char m_ucReserved; }; //------------------------------------------------------------- //- SMD2Frame //- Frame information for the model file struct SMD2Frame { float m_fScale[3]; float m_fTrans[3]; char m_caName[16]; SMD2Vert * m_pVerts; //Cleans up after itself SMD2Frame() { m_pVerts = 0; } ~SMD2Frame() { if(m_pVerts) delete [] m_pVerts; } }; //------------------------------------------------------------- //- SMD2Tri //- Triangle information for the MD2 struct SMD2Tri { unsigned short m_sVertIndices[3]; unsigned short m_sTexIndices[3]; }; //------------------------------------------------------------- //- SMD2TexCoord //- Texture coord information for the MD2 struct SMD2TexCoord { float m_fTex[2]; }; //------------------------------------------------------------- //- SMD2Skin //- Name of a single skin in the md2 file struct SMD2Skin { char m_caSkin[64];//filename CImage m_Image;//Image file ready for texturing }; //------------------------------------------------------------- // CTIMER - // author: Evan Pipho ([evan-:-codershq-:-com]) - // date : Jul 10, 2002 - //------------------------------------------------------------- class CMd2 : public CModel { public: //Set skin to one of the files specified in the md2 files itself void SetSkin(unsigned int uiSkin); //Set skin to a different image void SetSkin(CImage& skin); //Load the file bool Load(const char * szFilename); //Render file at the initial position void Render(); //Render the file at a certain frame void Render(unsigned int uiFrame); //Animate the md2 model (start and end frames of 0 and 0 will loop through the WHOLE model void Animate(float fSpeed = 30.0f, unsigned int uiStartFrame = 0, unsigned int uiEndFrame = 0, bool bLoop = true); //constructors/destructo CMd2(); CMd2(const char * szFile); ~CMd2(); private: CTimer m_Timer; //file header information SMD2Header m_Head; //Frame information SMD2Frame * m_pFrames; //Triangles SMD2Tri * m_pTriangles; //Texure coords SMD2TexCoord * m_pTexCoords; //Skin files SMD2Skin * m_pSkins; //Interpolated vertices SMD2Vert * m_pVerts; //Current skin unsigned int m_uiSkin; //Using a custom skin? bool m_bIsCustomSkin; //The custom skin CImage * m_pCustSkin; }; | |
What I would like to achieve is in REBOL: 1) Declaring in REBOL the struct schemes identically as a in the C way 2) read the file containing the datas to fill the declared struct 3) attribute to struct the rode data from the file 4)can interact freely with REBOL common fonctions | |
older newer | first last |