1. An elegant solution?
- Posted by Michael Sabal <mjs at OSA.ATT.NE.JP> Feb 02, 1999
- 485 views
- Last edited Feb 03, 1999
OK, some people want structures or records or whatever, but implementing = them would break code. Let's try this on for size, taking inspiration = from routine_id. Every sequence, whether top level or sublevel, has at = least one attribute flag for the length of the sequence. Let's add = another flag called "locked". This flag is boolean, so it won't really = use any significant memory. Whenever a sequence is created, locked =3D = false. So far, everything is backwards compatible. Now, we add two new = procedures and two functions to the internal library. For example: sequence point3D This sets the locked attribute to true and initializes the three = positions to garbage (or 0). Now, in append, prepend, &, and left-value = of point3D, the change fails, generating an error. If you set an atom = as "Hello", you get an error, so this would appear as the same. So, point3D =3D {24,44,49} -- this is OK point3D =3D {24,44,49,40} -- checks if sequence - OK; check if locked - = yes; check locked length - 3; -- check if assignment is the right length - NO, so error. If yes, then = check if each element is the right -- type. If no, then type-check error. point3D =3D {24,44} -- no good, same as above. point3D[2] =3D 44 -- this is OK point3D[3] =3D 44.5 -- generates a type-check failure after checking for = locked status. point3D =3D append(point3D,...)=20 point3D =3D prepend(point3D,...) point3D =3D point3D & ... -- All these generate errors for trying to change the length of a locked = sequence. To unlock the sequence and return it to normal operations, unlock_sequence(point3D) To check its locked status, if is_locked(point3D) then ... end if And to check the validity of elements of a sequence of locked sequences, = we would have to use if equals_sequence(point3Dgrid[1],{"integer","integer","integer"}) then ... -- returns 1 if true, 0 if false end if Would this be an acceptable / elegant solution? It would not define any = new types, shouldn't break existing code, and would allow a Euphorized = structure syntax. Ideas? Michael J. Sabal mjs at osa.att.ne.jp http://home.att.ne.jp/gold/mjs/index.html
2. Re: An elegant solution?
- Posted by Raude Riwal <rauder at THMULTI.COM> Feb 02, 1999
- 476 views
Although I'm not very intelligent, I understood everything. So I think it is the elegant solution. You could also write: global function structure(sequence s) return is_locked(s) end function .... if structure(foo) then puts(1,"you're right") endif but there's no "." or "::" . (on my french keyboard it's faster to type 2 ":" than "shift-." ---------- From: Michael Sabal To: EUPHORIA at LISTSERV.MUOHIO.EDU Subject: An elegant solution? Date: Tuesday 2 February 1999 23:49 <deleted...> To check its locked status, if is_locked(point3D) then ... end if
3. An elegant solution?
- Posted by Michael Sabal <mjs at OSA.ATT.NE.JP> Feb 06, 1999
- 459 views
My e-mailer has had some trouble lately, and nobody who's still talking = about structures has addressed this suggestion, so I'm sending it again. >OK, some people want structures or records or whatever, but = implementing them would break code. Let's try this on for size, taking = inspiration from routine_id. Every sequence, whether top level or = sublevel, has at least one attribute flag for the length of the = sequence. Let's add another flag called "locked". This flag is = boolean, so it won't really use any significant memory. Whenever a = sequence is created, locked =3D false. So far, everything is backwards = compatible. Now, we add two new procedures and two functions to the = internal library. For example: sequence point3D This sets the locked attribute to true and initializes the three = positions to garbage (or 0). Now, in append, prepend, &, and left-value = of point3D, the change fails, generating an error. If you set an atom = as "Hello", you get an error, so this would appear as the same. So, point3D =3D {24,44,49} -- this is OK point3D =3D {24,44,49,40} -- checks if sequence - OK; check if locked - = yes; check locked length - 3; -- check if assignment is the right length - NO, so error. If yes, then = check if each element is the right -- type. If no, then type-check error. point3D =3D {24,44} -- no good, same as above. point3D[2] =3D 44 -- this is OK point3D[3] =3D 44.5 -- generates a type-check failure after checking for = locked status. point3D =3D append(point3D,...)=20 point3D =3D prepend(point3D,...) point3D =3D point3D & ... -- All these generate errors for trying to change the length of a locked = sequence. To unlock the sequence and return it to normal operations, unlock_sequence(point3D) To check its locked status, if is_locked(point3D) then ... end if And to check the validity of elements of a sequence of locked sequences, = we would have to use if equals_sequence(point3Dgrid[1],{"integer","integer","integer"}) then ... -- returns 1 if true, 0 if false end if Would this be an acceptable / elegant solution? It would not define any = new types, shouldn't break existing code, and would allow a Euphorized = structure syntax. Ideas? Michael J. Sabal mjs at osa.att.ne.jp http://home.att.ne.jp/gold/mjs/index.html