Lou@cup.portal.com (09/26/88)
Greetings. I never though I'd be using HyperCard until somebody told me they wanted to catalog a few thousand dogs and track their ancestors and progeny. Well, I sat down with Goodman's book, then I bought the Apple HyperCard Script Language Guide and I was moving along. I tried building a few tiny stacks that would help me learn the techniques I'd need for the larger database and to help me become familiar with HyperCard's syntax and such. It was quite a joy until I discovered some speed problems, notably with operations that require sorting and finding data. For example, I have this pointless game called "Bandit." Every card features a player (bg field "Name"), and a list of things he "owns" (scrolling bg field "Stuff"). The highlight of a player's life is "stealing" a piece of data from another player. So, at any card, a player can click on a button labeled "Steal..." and up pops a list of players, or a list of all the different things across all the cards. The user clicks on the item he wants, or the player he wants to steal from, and an item is pulled from the appropriate person and added to the stealing player's list of stuff. Pretty moronic, but it requires several programming tasks: - Culling a list of players in the game from all the cards - Culling a list of individual items from all the players' stuff - Preserving point-and-click interaction The problem: It takes HyperTalk forever to a) sort a container or b) to test for the exact occurance of an item when producing a list of different items in the stack: i.e. there may be several "Roller Skates" floating around in players' bags of stuff, but I want only one "Roller Skate" to show up when the user requests a list of things in the "world". The solution seems to be to get XFCNs to overcome this problem, and I have done this. But what bothers me it that these are functions I already know how to write in Pascal, and I really don't like having to include foreign code in something I might want to sell or give away one day. The person who wrote the "find" XFCN i'm using wants a $10 license from me... does that mean $10 of every copy I sell goes to him? Does it mean I can't give the stack away? I'm using HyperTalk because I want to avoid having to learn classic "Mac Programming". Although I'm very familiar with "standard", terminal-type pascal, I don't recognize anything I'm familiar with in the published listings of XCMDs and XFCNs. Is there such a thing as an "easy" XFCN? I mean, a bubble sort is pretty easy in Pascal. How much stuff do I have to add to a procedure like that to turn it into a HyperCard resource? (I'm using Turbo Pascal 1.1, which is supposed to support the necessary stuff for XCMDs and XFCNs). Please help point me in the right direction (The Apple Guide section on X-Stuff is a little ahead of me). -Bill P.S.: Anyone know why the round function rounds UP for fractions = .5 if the whole part of the number is odd, but rounds DOWN for fractions equal to .5 if the whole part of the number is even? For example, round(1.5) is 2, but round(4.5) is 4. _____________________________________________________________________ _ Portal: Lou@portal.uucp _ Bill Marriott Northwestern University: innen@nuacc.bitnet _ GEnie: W.MARRIOTT CI$: 72047,2770 _____________________________________________________________________
landman%hanami@Sun.COM (Howard A. Landman) (09/28/88)
In article <9468@cup.portal.com> Lou@cup.portal.com writes: >P.S.: Anyone know why the round function rounds UP for fractions = .5 >if the whole part of the number is odd, but rounds DOWN for fractions >equal to .5 if the whole part of the number is even? For example, >round(1.5) is 2, but round(4.5) is 4. The IEEE floating point standard specifies that rounding must be done in this way. The motivation is to avoid bias in rounding, that is, you don't want rounding to have the property that rounding a random number has a different expectation than the random number itself. The rounding toward even numbers prevents this, since half the .5's round up while the other half round down, and has the side benefit that it leaves a zero in the LSB so that future operations (like divide by two) have a tendency to be a hair more accurate. It also has the advantage that positive and negative numbers round identically, that is, it is always true that round(-x) = -round(x). You can reconstruct the "old-style" rounding, if you must, by adding .5 and then truncating. Fair enough? Howard A. Landman landman@hanami.sun.com UUCP: sun!hanami!landman
Scot.Kamins@f555.n125.z1.FIDONET.ORG (Scot Kamins) (09/28/88)
Best book on the subject of XCMDs is Gary Bond's XCMD's For HyperCard (MIS Press). As to the strange rounding, HyperTalk calls the Apple SANE math routines in the ROM: that's the source of the strangeness. -- Scot Kamins - via FidoNet node 1:125/406 UUCP: ...!sun!hoptoad!fidogate!555!Scot.Kamins ARPA: Scot.Kamins@f555.n125.z1.FIDONET.ORG