home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / csmpdigest / csmp-digest-v3-005 < prev    next >
Text File  |  2010-09-21  |  69KB  |  1,863 lines

  1. Received-Date: Wed, 16 Mar 1994 16:43:31 +0100
  2. From: pottier@clipper.ens.fr (Francois Pottier)
  3. Subject: C.S.M.P. Digest, Issue 3.005
  4. To: csmp-digest@ens.fr
  5. Date: Wed, 16 Mar 94 16:43:25 MET
  6. X-Mailer: ELM [version 2.3 PL11]
  7. Errors-To: listman@ens.fr
  8. Reply-To: pottier@clipper.ens.fr
  9. X-Sequence: 6
  10.  
  11. C.S.M.P. Digest             Wed, 16 Mar 94       Volume 3 : Issue 5
  12.  
  13. Today's Topics:
  14.  
  15.         AppleScript: Compiled Script of Applets?
  16.         Communications Tool Box Experts?
  17.         Execution speed of compiled code
  18.         How do I : find out more about an open resource file ?
  19.         PopUpMenuControl v. 'mctb', help help
  20.         TextEdit caret
  21.         What language should I learn?
  22.  
  23.  
  24.  
  25. The Comp.Sys.Mac.Programmer Digest is moderated by Francois Pottier
  26. (pottier@clipper.ens.fr).
  27.  
  28. The digest is a collection of article threads from the internet newsgroup
  29. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  30. regularly and want an archive of the discussions.  If you don't know what a
  31. newsgroup is, you probably don't have access to it.  Ask your systems
  32. administrator(s) for details.  If you don't have access to news, you may
  33. still be able to post messages to the group by using a mail server like
  34. anon.penet.fi (mail help@anon.penet.fi for more information).
  35.  
  36. Each issue of the digest contains one or more sets of articles (called
  37. threads), with each set corresponding to a 'discussion' of a particular
  38. subject.  The articles are not edited; all articles included in this digest
  39. are in their original posted form (as received by our news server at
  40. nef.ens.fr).  Article threads are not added to the digest until the last
  41. article added to the thread is at least two weeks old (this is to ensure that
  42. the thread is dead before adding it to the digest).  Article threads that
  43. consist of only one message are generally not included in the digest.
  44.  
  45. The digest is officially distributed by two means, by email and ftp.
  46.  
  47. If you want to receive the digest by mail, send email to listserv@ens.fr
  48. with no subject and one of the following commands as body:
  49.     help                        Sends you a summary of commands
  50.     subscribe csmp-digest Your Name    Adds you to the mailing list
  51.     signoff csmp-digest            Removes you from the list
  52. Once you have subscribed, you will automatically receive each new
  53. issue as it is created.
  54.  
  55. The official ftp info is //ftp.dartmouth.edu/pub/csmp-digest.
  56. Questions related to the ftp site should be directed to
  57. scott.silver@dartmouth.edu. Currently no previous volumes of the CSMP
  58. digest are available there.
  59.  
  60. Also, the digests are available to WAIS users as comp.sys.mac.programmer.src.
  61.  
  62.  
  63. -------------------------------------------------------
  64.  
  65. >From yjc@po.cwru.edu (Jerome Chan)
  66. Subject: AppleScript: Compiled Script of Applets?
  67. Date: Sat, 26 Feb 1994 13:05:59 -0500
  68. Organization: TofuSoft
  69.  
  70. What are the advantages of Compiled scripts and Applets? Are they both the
  71. same? Can I run multiple scripts/applets at a time?
  72.  
  73. -- 
  74.  The Evil Tofu (Only Human)
  75.  
  76. +++++++++++++++++++++++++++
  77.  
  78. >From js12@gte.com (John Schettino)
  79. Date: Mon, 28 Feb 1994 13:02:42 GMT
  80. Organization: GTE Labs, Waltham MA
  81.  
  82. In article <yjc-260294130559@b61539.student.cwru.edu>
  83. yjc@po.cwru.edu (Jerome Chan) writes:
  84.  
  85. > What are the advantages of Compiled scripts and Applets? Are they both the
  86. > same? Can I run multiple scripts/applets at a time?
  87. > -- 
  88. >  The Evil Tofu (Only Human)
  89.  
  90. compiled scripts correspond to reusable compiled libs in other
  91. languages. You cannot "run" them, you access them using:
  92.  
  93. -- this is meant to be applescript
  94. set myfuncts to load script file "myhd:mylibs:functs"
  95.  
  96. -- where "myhd:mylibs:functs" is the full path to the file you saved 
  97. -- as a compiled script.
  98.  
  99. -- assume that there are two handlers in the file functs called foo and
  100. bar. you
  101. -- access them using:
  102. myfuncts's foo()
  103. myfuncts's bar()
  104.  
  105. -- 'load script' is an applescript extention (found in System
  106. Folder:Extentions:Scripting Additions:Load Script) and has a dictionary
  107. that you can see by droping this file on the script editor.
  108.  
  109.  
  110. John Schettino - js12@gte.com
  111. GTE Laboratories, Inc
  112.  
  113. +++++++++++++++++++++++++++
  114.  
  115. >From minshull.m@applelink.apple.com (Mark Minshull)
  116. Date: Tue, 1 Mar 1994 23:02:53 GMT
  117. Organization: OpenDoc Engineering
  118.  
  119. In article <CLxqwK.GBL@gte.com>, js12@gte.com (John Schettino) wrote:
  120.  
  121. > In article <yjc-260294130559@b61539.student.cwru.edu>
  122. > yjc@po.cwru.edu (Jerome Chan) writes:
  123. > > What are the advantages of Compiled scripts and Applets? Are they both the
  124. > > same? Can I run multiple scripts/applets at a time?
  125. > > 
  126. > > -- 
  127. > >  The Evil Tofu (Only Human)
  128. > compiled scripts correspond to reusable compiled libs in other
  129. > languages. You cannot "run" them, you access them using:
  130.  
  131. You *can* run compiled scripts by using the "run script" command, or
  132. "telling" the script object to run.  For example, consider the script
  133. below, saved in the file "hd:folder:hello world" as a compiled script: 
  134.  
  135.          display dialog "hello world"
  136.  
  137.       on foo(x)
  138.         return x + 2
  139.    end foo
  140.  
  141.       on bar(y)
  142.         return y - 2
  143.    end bar
  144.  
  145. You can execute this as follows:
  146.  
  147.       run script file "hd:folder:hello world"
  148.  
  149. which would display a dialog.  If you want to load the script as a library
  150. and run it you would script:
  151.  
  152.       set myFooLib to load script file "hd:folder:hello world"
  153.       tell myFooLib
  154.       run         -- display's a dialog
  155.       foo(2)      --   => 4
  156.       bar(2)      --   => 0
  157.    end tell
  158.  
  159. Finally, "applets" are AppleScripts saved as small applications.  You can
  160. have any number of them running at once (up to the limit of memory).  If
  161. it's a "stay open" script application one can access it's handlers as
  162. follows:
  163.  
  164.    tell application "hello world"    -- launches application if not running
  165.       run         -- display's a dialog
  166.       foo(2)      --   => 4
  167.       bar(2)      --   => 0
  168.             quit        -- quit's the script application
  169.    end tell     
  170.  
  171. Mark
  172. -- 
  173. Mark Minshull                       :
  174. OpenDoc Engineering Manager         :          Apple usually doesn't care 
  175. Apple Computer, Inc.                :          what I say... When they do
  176. 1 Infinite Loop, MS 303-3A          :          my opinions are my own.
  177. Cupertino, CA  95014                :    
  178.  
  179. +++++++++++++++++++++++++++
  180.  
  181. >From js12@gte.com (John Schettino)
  182. Date: Wed, 2 Mar 1994 12:36:36 GMT
  183. Organization: GTE Labs, Waltham MA
  184.  
  185. In article <minshull.m-010394150253@minshullmac.apple.com>
  186. minshull.m@applelink.apple.com (Mark Minshull) writes:
  187.  
  188. > In article <CLxqwK.GBL@gte.com>, js12@gte.com (John Schettino) wrote:
  189. > > In article <yjc-260294130559@b61539.student.cwru.edu>
  190. > > yjc@po.cwru.edu (Jerome Chan) writes:
  191. > > 
  192. > > > What are the advantages of Compiled scripts and Applets? Are they both the
  193. > > > same? Can I run multiple scripts/applets at a time?
  194. > > > 
  195. > > > -- 
  196. > > >  The Evil Tofu (Only Human)
  197. > > 
  198. > > compiled scripts correspond to reusable compiled libs in other
  199. > > languages. You cannot "run" them, you access them using:
  200. > > 
  201. > You *can* run compiled scripts by using the "run script" command, or
  202. > "telling" the script object to run.  For example, consider the script
  203. > below, saved in the file "hd:folder:hello world" as a compiled script: 
  204. >                  display dialog "hello world"
  205. >           on foo(x)
  206. >             return x + 2
  207. >    end foo
  208. >           on bar(y)
  209. >             return y - 2
  210. >    end bar
  211. > You can execute this as follows:
  212. >           run script file "hd:folder:hello world"
  213. > which would display a dialog.  If you want to load the script as a library
  214. > and run it you would script:
  215. >           set myFooLib to load script file "hd:folder:hello world"
  216. >           tell myFooLib
  217. >       run         -- display's a dialog
  218. >       foo(2)      --   => 4
  219. >       bar(2)      --   => 0
  220. >    end tell
  221.  
  222. Yes, you can *load* a compiled script into your script and send it a
  223. run command, but I guessed that he meant "Can you run a compiled script
  224. *from the finder*" With this interpretation, the answer is "no". Your
  225. answer is correct, and (I think) so is mine!
  226.  
  227. John Schettino - js12@gte.com
  228. GTE Laboratories, Inc
  229.  
  230. ---------------------------
  231.  
  232. >From tel@adimail.uucp (Terry Monks)
  233. Subject: Communications Tool Box Experts?
  234. Date: Mon, 28 Feb 1994 19:08:40 GMT
  235. Organization: Automata Design, Inc.
  236.  
  237. Are there any CTB experts out there? I need to send a setup string
  238. to my USR modem from with a program. Not the CTB setup string,
  239. but a AT&B1&H1 sort of thing. I know I can change the modem type
  240. to Custom and change the modem setup string, but how do you do
  241. this from within a CTB program? And where (if anywhere) is this
  242. documented. How does the Apple Modem Tool know about the different
  243. modes, and can I add one of my own.
  244.  
  245. I do (of course) have the Inside Mac CTB document, that is silent
  246. on these interesting points...
  247.  
  248. Tel
  249.  
  250. -- 
  251. Terry Monks    tel@adiva.com    Automata Design Inc    (703) 742-9400
  252.  
  253.  
  254. +++++++++++++++++++++++++++
  255.  
  256. >From ejw@pacersoft.com (Erik James Walter)
  257. Date: 1 Mar 94 21:01:43 GMT
  258. Organization: Pacer Software, Inc.
  259.  
  260. In article <1994Feb28.190840.25604@adimail.uucp> Terry Monks,
  261. tel@adimail.uucp writes:
  262. >Are there any CTB experts out there? I need to send a setup string
  263. >to my USR modem from with a program. Not the CTB setup string,
  264. >but a AT&B1&H1 sort of thing. I know I can change the modem type
  265. >to Custom and change the modem setup string, but how do you do
  266. >this from within a CTB program? And where (if anywhere) is this
  267. >documented. How does the Apple Modem Tool know about the different
  268. >modes, and can I add one of my own.
  269. >
  270. >I do (of course) have the Inside Mac CTB document, that is silent
  271. >on these interesting points...
  272. >
  273.  
  274. For starters, you could simply use the Serial tool and send the data
  275. directly
  276. to the modem.   If you look at GetConfig and SetConfig for tools, I think
  277. that you'll find the information you need on setting a custom modem and
  278. changing the tool settings.  Inside CTB doesn't say it directly, but you
  279. can pass just one or two settings in the SetConfig call and it won't
  280. affect
  281. anything but the settings you pass to it.
  282.  
  283. If you want to do it with a custom modem type, there is no way to change
  284. the
  285. modem file from CTB, but you can just open the file yourself if you so
  286. choose to (Not a good idea, however).
  287.  
  288. If timing isn't critical, why not just send the string after opening the
  289. connection??
  290.  
  291.  
  292. +-------------------------------------------++-------------------------
  293. ---+
  294. | A man gazing at the stars is at the mercy ||     Erik Walter           
  295.  | 
  296. | of every puddle on the road.              ||     Macintosh Engineer    
  297.  |
  298. | "Travel is lethal to prejudice."          ||     Pacer Software, Inc.  
  299.  |  
  300. | MARK TWAIN                                ||                           
  301.  |
  302. +-------------------------------------------++-------------------------
  303. ---+
  304.  
  305. +++++++++++++++++++++++++++
  306.  
  307. >From gurgle@netcom.com (Pete Gontier)
  308. Date: Wed, 2 Mar 1994 00:36:05 GMT
  309. Organization: cellular
  310.  
  311. I'm no CTB expert, but what the hell? This post has been here long
  312. enough that I might as well take a shot at it.
  313.  
  314. tel@adimail.uucp (Terry Monks) writes:
  315.  
  316. >Are there any CTB experts out there? I need to send a setup string
  317. >to my USR modem from with a program. Not the CTB setup string, but a
  318. >AT&B1&H1 sort of thing. I know I can change the modem type to Custom
  319. >and change the modem setup string, but how do you do this from within a
  320. >CTB program?
  321.  
  322. You don't. The whole point of the CTB is that your program does not have
  323. any control over the connection that the connection tool doesn't want
  324. you to have. In most cases, this means you have very little control.
  325. This is a feature -- you don't *want* control, because not only is
  326. control a PITA, but what you get in exchange is the ability to use your
  327. software with AppleTalk, TCP, and any other sort of connection for which
  328. you have a tool.
  329.  
  330. One thing you might try is to use the Serial tool to send AT commands,
  331. but if you'll watch the progress window as the modem tool opens a
  332. connection, you'll see it does a pretty thorough job of blowing away any
  333. previous configuration by using 'ATZ'. At least it does not do 'AT&F';
  334. you might be able to slide something past it because of that.
  335.  
  336. If I understand correctly, you might not be able to guess which serial
  337. port the modem is hooked up to, because the CTB allows programs to
  338. register serial ports which are not the modem port or the printer port.
  339. This would tend to foil attempts to tweak the modem with the Serial
  340. Manager, as well.
  341.  
  342. You might just choose to skip the modem tool entirely and assume that
  343. the serial tool is connected to a modem. You would have to write
  344. your own code to send AT commands and parse responses. This is not
  345. particularly difficult but can be frustrating if you have never done it
  346. before. Getting it really robust is another story; there are hundreds of
  347. modems out there, each with its own interpretation of the Hayes command
  348. set.
  349.  
  350. >And where (if anywhere) is this documented.
  351.  
  352. It's not. It's implicit in the way the CTB works. To explain it would be
  353. to explicitly document how to bypass the CTB.
  354.  
  355. >How does the Apple Modem Tool know about the different modes, and can I
  356. >add one of my own.
  357.  
  358. In versions earlier than 1.5, I dunno. In 1.5, just select "Modify this
  359. Menu..." from the 'Modem' popup menu. In my limited experience I have
  360. done configurations for an Okitel 9600 and a Global Village TelePort
  361. Gold. It's not hard. It's definitely the way to go if you have the
  362. option.
  363.  
  364. >I do (of course) have the Inside Mac CTB document, that is silent
  365. >on these interesting points...
  366.  
  367. That's because it's a general-case document and tries to keep its grubby
  368. little fingers out of the domain of any particular tool. :-)
  369. -- 
  370.  Pete Gontier, CTO, Integer Poet Software; gurgle@netcom.com
  371.  
  372. ---------------------------
  373.  
  374. >From schiffer@dispair.stsci.edu (Francis H. Schiffer 3rd)
  375. Subject: Execution speed of compiled code
  376. Date: Tue, 1 Mar 1994 17:54:23 GMT
  377. Organization: Self
  378.  
  379. I have noticed a number of posts recently asking about how to achieve the 
  380. best speed of processing on a Macintosh.  The responses have said little
  381. about
  382. the effects of your compiler, whereas the benchmarks published for
  383. workstations
  384. tend to focus on the effects of your compiler on benchmark speeds.  
  385.  
  386. I attempted to see what are the effects of the compiler on the execution 
  387. speeds of a small number of benchmark programs using a IIfx running A/UX.
  388. I had four compilers that I could use:
  389.      cc    = the A/UX compiler supplied by Apple and Motorola,
  390.      gcc   = the Gnu compiler version 2.5.7 ported to A/UX,
  391.      TC    = Think C version 6.0.1, and
  392.      SC++  = Symmantec C++ version 6.0.1.
  393. The programs were benchmarks that have been used for workstation
  394. benchmarking
  395. with the minimum modifications necessary to run within the MacOS and/or
  396. A/UX
  397. environment.  For A/UX that means no modifications and for the MacOS
  398. usually 
  399. only the inclusion of prototypes.  As these are ANSI style programs, the 
  400. Think console was used for output, but that processing was entirely outside
  401. the timed sections.  In each case the benchmark times the computational
  402. portion
  403. of the program for a sufficient number of iterations to ensure that the
  404. total
  405. duration time was small compared to the timing quanta (typically 
  406. 16.67 milliseconds).  In each case the application was built using the best
  407. level of optimization offered by the compiler.
  408.  
  409. The results are shown in the following table where I have normalized the
  410. results
  411. to the speed of the fastest program .  The duration is the time it took the
  412.  
  413. fastest version of the program to execute the timed portion of the
  414. benchmark.
  415.  
  416.                        cc      gcc      TC     SC++   Duration
  417. Towers of Hanoi        1.00    0.79    0.81    0.68   37.4 sec
  418. Heapsort               0.79    1.00    0.77    0.50   24.4 sec
  419. Sieve of Eratosthenes  0.91    1.00    0.97    0.76   83.3 sec
  420.  
  421. It should be noted that part of the slowness of the MacOS compiled versions
  422. may well be due to the fact that the timing routines on the A/UX side
  423. discount
  424. the system time from the running time, whereas the MacOS run times include
  425. the system time.  All of the runs were done on a lightly loaded system, so
  426. the effects should be small.  I, unfortunately, do not have the option to
  427. take
  428. down A/UX to run on a purely native MacOS to get a measure of this bias.
  429.            skip
  430. -- 
  431. Francis H Schiffer 3rd  schiffer@stsci.edu - my opinions only, those of
  432. skip@dispair.stsci.edu  stscic::schiffer   - my employer are unknown to me
  433.  
  434. ---------------------------
  435.  
  436. >From reinkeha@dunx1.ocs.drexel.edu (Harry A. Reinke)
  437. Subject: How do I : find out more about an open resource file ?
  438. Date: Wed, 23 Feb 1994 14:52:09 GMT
  439. Organization: Drexel University, Phila. Pa.
  440.  
  441. I have been having problems with some resources, I do a CountResources and
  442. I get 2 or 3 more than are available in my resource file.  The resource
  443. type is 'hdrs' so I know that the syste and other open resource files do
  444. not have any such resources.
  445.  
  446. Am I writeing a resource without removing the old ?  I remember something
  447. about if you're not carefull you can save a particular resource type and
  448. number without destroying the prvious which causes problems.
  449.  
  450. I have used HomeResFile and its return numbers that I didn't expect (like
  451. 2546 instead of 2640) but is not part of the system/ROM.  How do I find
  452. out more about an open res file if I have its ref num ?  I would love to
  453. associate a filename with the numbers returned from HomeResFile.
  454.  
  455. Thanks.
  456.  
  457.  
  458.  
  459. +++++++++++++++++++++++++++
  460.  
  461. >From walrathw@rferl.org (WalrathW)
  462. Date: 28 Feb 94 11:18:29 -0500
  463. Organization: RFE/RL Inc.
  464.  
  465. In article <CLoMMx.AE7@Dunx1.OCS.Drexel.Edu>
  466. reinkeha@dunx1.ocs.drexel.edu (Harry A. Reinke) writes:
  467.  
  468. > I have been having problems with some resources, I do a CountResources and
  469. > I get 2 or 3 more than are available in my resource file.  The resource
  470. > type is 'hdrs' so I know that the syste and other open resource files do
  471. > not have any such resources.
  472. > Am I writeing a resource without removing the old ?  I remember something
  473. > about if you're not carefull you can save a particular resource type and
  474. > number without destroying the prvious which causes problems.
  475. > I have used HomeResFile and its return numbers that I didn't expect (like
  476. > 2546 instead of 2640) but is not part of the system/ROM.  How do I find
  477. > out more about an open res file if I have its ref num ?  I would love to
  478. > associate a filename with the numbers returned from HomeResFile.
  479. > Thanks.
  480. You can use the FILE dcmd in Macsbug to accomplish this. If you don't
  481. have it, check ftp.apple.com. If you don't find it there, send mail and
  482. i'll dig it up for you.
  483.  
  484. You could also just write a little hack to walk through the FCB data
  485. structures (or better yet use _PBGetFCBInfo). I presume there is info
  486. on this in New Inside Mac:Files, and you should also find something in
  487. ThinkRef. "Debugging Macintosh Software w/ Macsbug" is a book worth
  488. having, and also another source of info on these topics.  
  489.  
  490. I started writing a little app last week to display resource chains and
  491. the resMap's of open resource files, but kind of tabled the project
  492. after finding the tool I wanted already written. I have code for
  493. walking a resMap as well as getting the file name of an open res file,
  494. given its refNum.  Mail me if you want any of this code. It's not
  495. polished since it wasn't for distribution, but I think I added some
  496. comments here and there   :-)   .
  497.  
  498. cheers,
  499. ______o0o______
  500.  Wayne Walrath
  501.  RFE/RL Inc.
  502.  
  503. +++++++++++++++++++++++++++
  504.  
  505. >From jim@brunner.wf.com (Jim Brunner)
  506. Date: 1 Mar 94 17:16:59 GMT
  507. Organization: (none)
  508.  
  509.  
  510. In article <1994Feb28.111834.340@dcvaxb.rferl.org>, you write:
  511. > In article <CLoMMx.AE7@Dunx1.OCS.Drexel.Edu>
  512. > reinkeha@dunx1.ocs.drexel.edu (Harry A. Reinke) writes:
  513. > > I have been having problems with some resources, I do a CountResources 
  514. and
  515. > > I get 2 or 3 more than are available in my resource file.  The 
  516. resource
  517. > > type is 'hdrs' so I know that the syste and other open resource files 
  518. do
  519. > > not have any such resources.
  520. > > 
  521. > > Am I writeing a resource without removing the old ?  I remember 
  522. something
  523. > > about if you're not carefull you can save a particular resource type 
  524. and
  525. > > number without destroying the prvious which causes problems.
  526.  
  527.  
  528. CountResources counts all resources in all resource files (you mention that 
  529. the type you are counting is not in other resource files like system but 
  530. you may want to do this anyway) "Count1Resources" only counts in the 
  531. current resource file.
  532.  
  533. As to if a resource file can contain the same resource type/id twice, the 
  534. answer is YES!  I had this problem once.  If you do an AddResource and the 
  535. resource already exists, there will be a second one added.  You'll need to 
  536. watch this.
  537.  
  538. ---
  539. Jim Brunner (jim@brunner.wf.com)
  540.  
  541. ---------------------------
  542.  
  543. >From first.ascent@mindlink.bc.ca (Alex Curylo)
  544. Subject: PopUpMenuControl v. 'mctb', help help
  545. Date: 28 Feb 94 01:38:42 GMT
  546. Organization: MIND LINK! - British Columbia, Canada
  547.  
  548. I have a DITL resource, used in a CTB setup, that has a popup menu control in
  549. it. Since the popup menu would look much more cool in color, I created a
  550. 'mctb' for it in ResEdit, which displays the menu correctly. But when the
  551. menu is popped up in the dialog courtesy of the Dialog Manager, it's in bogus
  552. black and white. Is there some trick to getting a popup menu control to know
  553. about an 'mctb' for its 'MENU'?
  554.  
  555. +++++++++++++++++++++++++++
  556.  
  557. >From leonardr@netcom.com (Leonard Rosenthol)
  558. Date: Mon, 28 Feb 1994 18:33:43 GMT
  559. Organization: Aladdin Systems, Inc.
  560.  
  561. In article <39602@mindlink.bc.ca>, first.ascent@mindlink.bc.ca (Alex
  562. Curylo) wrote:
  563.  
  564. > I have a DITL resource, used in a CTB setup, that has a popup menu control in
  565. > it. Since the popup menu would look much more cool in color, I created a
  566. > 'mctb' for it in ResEdit, which displays the menu correctly. But when the
  567. > menu is popped up in the dialog courtesy of the Dialog Manager, it's in bogus
  568. > black and white. Is there some trick to getting a popup menu control to know
  569. > about an 'mctb' for its 'MENU'?
  570. >
  571.      No trick - it doesn't work!   The PopUpCDEF doesn't load the 'mctb'
  572. resource due to visual problems reported in earlier versions of same...
  573.  
  574. Leonard
  575. P.S. Hey Jon - this should probably go in the FAQ!
  576. --------------------------------------------------------------------------
  577. Leonard Rosenthol                      Internet:       leonardr@netcom.com
  578. Director of Advanced Technology        AppleLink:      MACgician
  579. Aladdin Systems, Inc.                  GEnie:          MACgician
  580.  
  581. +++++++++++++++++++++++++++
  582.  
  583. >From t.g.finstad@fys.uio.no (Terje Finstad)
  584. Date: Mon, 28 Feb 1994 20:03:40
  585. Organization: Dept. Physics, Univ. Oslo
  586.  
  587. In article <leonardr-280294103343@leonardr.slip.netcom.com>,
  588. leonardr@netcom.com (Leonard Rosenthol) wrote:
  589. > In article <39602@mindlink.bc.ca>, first.ascent@mindlink.bc.ca (Alex
  590. > Curylo) wrote:
  591. > > I have a DITL resource, used in a CTB setup, that has a popup menu control in
  592. > > it. Since the popup menu would look much more cool in color, I created a
  593. > > 'mctb' for it in ResEdit, which displays the menu correctly. But when the
  594. > > menu is popped up in the dialog courtesy of the Dialog Manager, it's in bogus
  595. > > black and white. Is there some trick to getting a popup menu control to know
  596. > > about an 'mctb' for its 'MENU'?
  597. >
  598. >      No trick - it doesn't work!   The PopUpCDEF doesn't load the 'mctb'
  599. > resource due to visual problems reported in earlier versions of same...
  600.  
  601. I may have totally misunderstood,
  602. I _had similar problems to what Alex Curylo. _Now I always get colors as I
  603. want to in the PopUp.  Am I currently doing things wrong then?
  604. I am just calling insertmenu(myMenuHandle, -1) on a hit in the popup area
  605. and then PopUpMenuSelect ,  ( I've heard this is outdated, is that it? ) On
  606. startUp I just do a myMenuHandle := getmenu(kPopUpMenuID);
  607. I had previously been led to belive I should call deletemenu after the menu
  608. had been closed/hidden by PopUpMenuSelect.  This caused the color to
  609. disappear. Now it does not. The menu does not get inserted multiple times
  610. in the menu list as far as I can tell )
  611.  
  612. Terje
  613.  
  614. +++++++++++++++++++++++++++
  615.  
  616. >From mspace@netcom.com (Brian Hall)
  617. Date: Tue, 1 Mar 1994 05:37:07 GMT
  618. Organization: Mark/Space Softworks
  619.  
  620. t.g.finstad@fys.uio.no (Terje Finstad) writes:
  621.  
  622. >I may have totally misunderstood,
  623. >I _had similar problems to what Alex Curylo. _Now I always get colors as I
  624. >want to in the PopUp.  Am I currently doing things wrong then?
  625.  
  626. No, you are just doing them differnt.  Alex is using (and Leonard replied
  627. about) the Popup Menu CDEF that was introduced with the CTB and made it into
  628. system software as of 7.0.  You are doing it "by hand" so to speak. There are
  629. valid reasons for doing it that way, but most CTB apps use the CDEF since
  630. they get it for "free".
  631.  
  632. -- 
  633. __________________________________________________________________________
  634. Brian Hall                                     Internet: mspace@netcom.com
  635. Mark/Space Softworks                             AppleLink, AOL: MARKSPACE
  636. Macintosh connectivity software.   info via anon ftp netcom.com:pub/mspace
  637.  
  638. +++++++++++++++++++++++++++
  639.  
  640. >From Alexander M. Rosenberg <alexr@apple.com>
  641. Date: Wed, 2 Mar 1994 08:58:25 GMT
  642. Organization: Hackers Anonymous
  643.  
  644. In article <leonardr-280294103343@leonardr.slip.netcom.com> Leonard Rosenthol,
  645. leonardr@netcom.com writes:
  646. > > I have a DITL resource, used in a CTB setup, that has a popup menu control
  647. in
  648. > > it. Since the popup menu would look much more cool in color, I created a
  649. > > 'mctb' for it in ResEdit, which displays the menu correctly. But when the
  650. > > menu is popped up in the dialog courtesy of the Dialog Manager, it's in
  651. bogus
  652. > > black and white. Is there some trick to getting a popup menu control to
  653. know
  654. > > about an 'mctb' for its 'MENU'?
  655. > >
  656. >      No trick - it doesn't work!   The PopUpCDEF doesn't load the 'mctb'
  657. > resource due to visual problems reported in earlier versions of same...
  658.  
  659. Actually, the problem is that the Popup CDEF (as of System 7.1) doesn't keep
  660. the menu in the menulist. 'mctb' resources are menu id referential and since
  661. the popup doesn't keep and defend an id, then 'mctb's can't be used.
  662.  
  663. Note that Inside the Macintosh Communications Toolbox and Inside Macintosh VI
  664. don't say anywhere that 'mctb' resources are supported for popups. It was a
  665. fluke. :-)
  666.  
  667. The workaround is to manually load a menu and associate it with the popup.
  668. MacApp uses this technique.
  669. ---------------------------------------------------------------------------
  670. -  Alexander M. Rosenberg  - INTERNET: alexr@apple.com      - Yoyodyne    -
  671. -  330 Waverley St., Apt B - UUCP:ucbvax!apple!alexr        - Propulsion  -
  672. -  Palo Alto, CA 94301     -                                - Systems     -
  673. -  (415) 329-8463          - Nobody is my employer so       - :-)         -
  674. -  (408) 974-3110          - nobody cares what I say.       -             -
  675.  
  676. ---------------------------
  677.  
  678. >From cnowak@bonnie.ics.uci.edu (Chris)
  679. Subject: TextEdit caret
  680. Date: 19 Feb 1994 15:50:08 -0800
  681. Organization: UC Irvine Department of ICS
  682.  
  683. I am working on a program, and have run into a slight snag.  I have a textedit
  684. field on a grey background, so the caret doesn't show up very well...
  685.  
  686. I have looked for a way to maybe change its color, or make it thicker but to
  687. no avail.
  688.  
  689. Any ideas?
  690.  
  691. Thanx, 
  692. Chris
  693.  
  694. -------------------------------------------------------------------------------
  695. Chris Nowak                |Why, yes, the world does revolve around me!
  696. cnowak@bonnie.ics.uci.edu  |Unfortunately I can't control how fast it rotates. 
  697. eapu109@orion.oac.uci.edu  | ...actually, it's giving me a headache... 
  698. -------------------------------------------------------------------------------
  699.  
  700. +++++++++++++++++++++++++++
  701.  
  702. >From peter@ncrpda.curtin.edu.au (Peter N Lewis)
  703. Date: 21 Feb 1994 11:56:16 +0800
  704. Organization: NCRPDA, Curtin University
  705.  
  706. cnowak@bonnie.ics.uci.edu (Chris) writes:
  707.  
  708. >I am working on a program, and have run into a slight snag.  I have a textedit
  709. >field on a grey background, so the caret doesn't show up very well...
  710.  
  711. Well, don't put the text on a grey background then!  Seriously, you shouldn't
  712. really do this without the user at least having control over the field,
  713. since the text will also be less readable.  Perhaps just use a very light grey
  714. to differentiate it from other fields or the background?
  715.  
  716. >I have looked for a way to maybe change its color, or make it thicker but to
  717. >no avail.
  718.  
  719. There is a TEHook for drawing the cursor if I remember correctly.  It's 
  720. presumably documented in NIM-TE.  It must be documented in IM somewhere,
  721. otherwise I wouldn't know about it...
  722.    Peter.
  723. -- 
  724. _______________________________________________________________________
  725. Peter N Lewis <peter.lewis@info.curtin.edu.au>       Ph: +61 9 368 2055
  726.  
  727. +++++++++++++++++++++++++++
  728.  
  729. >From Here@There (Someone)
  730. Date: 1 Mar 1994 21:25:19 GMT
  731. Organization: Large Fuzzy Room
  732.  
  733. In article <2k68jg$cvq@bonnie.ics.uci.edu>, cnowak@bonnie.ics.uci.edu
  734. (Chris) wrote:
  735. > I am working on a program, and have run into a slight snag.  I have a textedit
  736. > field on a grey background, so the caret doesn't show up very well...
  737. > I have looked for a way to maybe change its color, or make it thicker but to
  738. Write a caret hook routine.  This allows you to draw the caret yourself, in
  739. this case you could change it to any color you like that would show up
  740. better against gray.  Or you could change the size.  Here's a small sample
  741. caret hook I writ a while ago, it's in assembly, sorry, but you get the
  742. point...
  743.  
  744. /* install the hook in the textedit record */
  745. (*WordHandle)->caretHook=myCaretDraw;
  746. ; The actual caret hook routine
  747.  
  748. myCaretDraw proc export
  749.  move.l (sp)+,d0             ; get the rectangle pointer
  750.  movem.l a2-a4/d3-d7,-(sp)   ; save registers
  751.  move.l d0,d3                ; store rect someplace safe
  752.  pea myBackColor
  753.  _RGBBackColor
  754. * caretOn is a global that you use to keep track of the caret state
  755. * now check your caretOn flag.  if true, turn it off, if false, turn it on 
  756.  move.w caretOn,d0
  757.  bne.s @itsOn
  758. * myForeColor is a global RGB color I was using
  759.  pea myForeColor       ; make the caret visible
  760.  _RGBForeColor
  761.  moveq #1,d0
  762.  bra.s @saveanddraw
  763. @itsOn  pea myBackColor      ; make the caret invisible
  764.  _RGBForeColor
  765.  moveq #0,d0
  766. @saveanddraw move.w d0,caretOn(a5) ; update the flag
  767.    move.l d3,-(sp)
  768.  _PaintRect
  769.  movem.l (sp)+,a2-a4/d3-d7     ; restore regs
  770.  rts     ; and go away
  771.  endp
  772.  
  773.  
  774. <TR>
  775. Somewhere, sometime
  776.  
  777. SPA FON
  778.  
  779. ---------------------------
  780.  
  781. >From lsweet@netcom.com (Lawrence Sweet)
  782. Subject: What language should I learn?
  783. Date: Mon, 21 Feb 1994 23:00:03 GMT
  784. Organization: NETCOM On-line Communication Services (408 241-9760 guest)
  785.  
  786. Hello...
  787.  
  788. I've been using the Mac for about two years and now am becoming interested in
  789. what is behind the curtain, so to speak...
  790.  
  791. I have no programming experience but I would like to learn something about how
  792. to do so, more as a hobbyist than anything else.  I have looked through a 
  793. variety of introductory programming texts for the Mac at my local bookstore,
  794. but I'm unsure which language to pursue or what book is well written enough to
  795. learn from.
  796.  
  797. Could you please give me some suggestions?
  798.  
  799. Thanks in advance, Larry
  800.  
  801. (email is appreciated, also)
  802. -- 
  803. Lawrence Sweet                               "Every wave is new until it breaks"San Diego, CA           lsweet@netcom.com             --Neil Young (1981)
  804.  
  805. +++++++++++++++++++++++++++
  806.  
  807. >From drickey@irus.rri.uwo.ca (Daniel W. Rickey)
  808. Date: 22 Feb 1994 16:59:48 GMT
  809. Organization: Imaging Research Labs
  810.  
  811.  
  812. For someone who has never programmed before, the language to start
  813. with is with Pascal.  A good book to start learning macinitosh
  814. programming
  815. is "Macinitosh Pascal Programming Primer".  I am not sure what books
  816. are
  817. good for learning to programme in Pascal.
  818.  
  819. Daniel W. Rickey
  820. drickey@.irus.rri.uwo.ca
  821.  
  822. Imaging Research Laboratories
  823. The J.P. Robarts Research Institute
  824. 100 Perth Drive
  825. London, Ontario
  826. CANADA  N6A 5K8
  827.  
  828. +++++++++++++++++++++++++++
  829.  
  830. >From 103t_english@west.cscwc.pima.edu
  831. Date: 23 Feb 94 00:10:41 MST
  832. Organization: (none)
  833.  
  834. In article <lsweetCLLJw6.AK2@netcom.com>, lsweet@netcom.com (Lawrence Sweet) writes:
  835. > Hello...
  836. > I've been using the Mac for about two years and now am becoming interested in
  837. > what is behind the curtain, so to speak...
  838. > I have no programming experience but I would like to learn something about how
  839. > to do so, more as a hobbyist than anything else.  I have looked through a 
  840. > variety of introductory programming texts for the Mac at my local bookstore,
  841. > but I'm unsure which language to pursue or what book is well written enough to
  842. > learn from.
  843. > Could you please give me some suggestions?
  844. > Thanks in advance, Larry
  845. > (email is appreciated, also)
  846. > -- 
  847. > Lawrence Sweet                               "Every wave is new until it breaks"San Diego, CA           lsweet@netcom.com             --Neil Young (1981)
  848.  
  849. At the risk of flames: learn SmallTalk/V.
  850.  
  851. It will give you access to the ToolBox, but at the same time, you will learn
  852. OOP from the ground up.
  853.  
  854.  
  855. Lawson
  856.  
  857. +++++++++++++++++++++++++++
  858.  
  859. >From gasser@masg1.epfl.ch (Laurent Gasser)
  860. Date: 23 Feb 1994 13:02:49 GMT
  861. Organization: Ecole Polytechnique Federale de Lausanne
  862.  
  863. DO NOT learn pascal from the reference given below.
  864.  
  865. The author have never used the WITH statement. In QuickDraw
  866. environement, it is incredible. Moreover, many examples are exactly
  867. illustrating bad pascal design. Il looks like they just translated C
  868. code into pascal.
  869.  
  870. If you want to learn pascal, get a book about pascal. Later on, when
  871. you consider yourself more at ease with the language, you can look
  872. around for a book about the Macintosh plateform. Don't mix both steps,
  873. you will get lost.
  874.  
  875. In article <2kddm4$462@falcon.ccs.uwo.ca>, drickey@irus.rri.uwo.ca (Daniel W. Rickey) writes:
  876. |> 
  877. |> For someone who has never programmed before, the language to start
  878. |> with is with Pascal.  A good book to start learning macinitosh
  879. |> programming
  880. |> is "Macinitosh Pascal Programming Primer".  I am not sure what books
  881. |> are
  882. |> good for learning to programme in Pascal.
  883. |> 
  884. |> Daniel W. Rickey
  885. |> drickey@.irus.rri.uwo.ca
  886. |> 
  887. |> Imaging Research Laboratories
  888. |> The J.P. Robarts Research Institute
  889. |> 100 Perth Drive
  890. |> London, Ontario
  891. |> CANADA  N6A 5K8
  892.  
  893. -- 
  894. Laurent Gasser (gasser@dma.epfl.ch)
  895.  
  896. I know very few ideas worth dying for, none is worth killing.
  897.  
  898. +++++++++++++++++++++++++++
  899.  
  900. >From drickey@irus.rri.uwo.ca (Daniel W. Rickey)
  901. Date: 23 Feb 1994 15:36:24 GMT
  902. Organization: Imaging Research Labs
  903.  
  904.  
  905. >DO NOT learn pascal from the reference given below.
  906.  
  907. >The author have never used the WITH statement. In QuickDraw
  908. >environement, it is incredible. Moreover, many examples are exactly
  909. >illustrating bad pascal design. Il looks like they just translated C
  910. >code into pascal.
  911.  
  912. >If you want to learn pascal, get a book about pascal. Later on, when
  913. >you consider yourself more at ease with the language, you can look
  914. >around for a book about the Macintosh plateform. Don't mix both steps,
  915. >you will get lost.
  916.  
  917. >In article <2kddm4$462@falcon.ccs.uwo.ca>, drickey@irus.rri.uwo.ca (Daniel W. >Rickey) writes:
  918. |> 
  919. |> For someone who has never programmed before, the language to start
  920. |> with is with Pascal.  A good book to start learning macinitosh
  921. |> programming
  922. |> is "Macinitosh Pascal Programming Primer".  I am not sure what books
  923. |> are
  924. |> good for learning to programme in Pascal.
  925. |> 
  926. |> Daniel W. Rickey
  927. |> drickey@.irus.rri.uwo.ca
  928. |> 
  929.  
  930.  
  931. I recommended the book as as a reasonable one for learning how to 
  932. programme the macintosh.  I agree that it is not a good one for
  933. learning
  934. Pascal.
  935. -- 
  936. >Laurent Gasser (gasser@dma.epfl.ch)
  937.  
  938. >I know very few ideas worth dying for, none is worth killing.
  939.  
  940.  
  941. Daniel W. Rickey
  942. drickey@.irus.rri.uwo.ca
  943.  
  944. Imaging Research Laboratories
  945. The J.P. Robarts Research Institute
  946. 100 Perth Drive
  947. London, Ontario
  948. CANADA  N6A 5K8
  949.  
  950. +++++++++++++++++++++++++++
  951.  
  952. >From peter@ncrpda.curtin.edu.au (Peter N Lewis)
  953. Date: 24 Feb 1994 10:56:50 +0800
  954. Organization: NCRPDA, Curtin University
  955.  
  956. gasser@masg1.epfl.ch (Laurent Gasser) writes:
  957.  
  958. >DO NOT learn pascal from the reference given below.
  959.  
  960. >The author have never used the WITH statement. In QuickDraw
  961. >environement, it is incredible. Moreover, many examples are exactly
  962.  
  963. Well, I know nothing about the book, so I can't comment on that.  But
  964. I will say that not using the WITH statement is a good idea.  The WITH
  965. statement leads to lots of very subtle errors, and generally should
  966. be avoided.
  967.    Peter.
  968. -- 
  969. _______________________________________________________________________
  970. Peter N Lewis <peter.lewis@info.curtin.edu.au>       Ph: +61 9 368 2055
  971.  
  972. +++++++++++++++++++++++++++
  973.  
  974. >From drickey@irus.rri.uwo.ca (Daniel W. Rickey)
  975. Date: 24 Feb 1994 15:00:54 GMT
  976. Organization: Imaging Research Labs
  977.  
  978. >In article <2kh51i$50q@ncrpda.curtin.edu.au>
  979. >peter@ncrpda.curtin.edu.au (Peter N Lewis) writes:
  980.  
  981. > gasser@masg1.epfl.ch (Laurent Gasser) writes:
  982. > >DO NOT learn pascal from the reference given below.
  983. > >The author have never used the WITH statement. In QuickDraw
  984. > >environement, it is incredible. Moreover, many examples are exactly
  985. > Well, I know nothing about the book, so I can't comment on that.  But
  986. > I will say that not using the WITH statement is a good idea.  The WITH
  987. > statement leads to lots of very subtle errors, and generally should
  988. > be avoided.
  989. >    Peter.
  990. > -- 
  991. > _______________________________________________________________________
  992. > Peter N Lewis <peter.lewis@info.curtin.edu.au>       Ph: +61 9 368 2055
  993.  
  994.  
  995. The with satement should not be avoided.  It should, however, be used
  996. with
  997. care.  One can get in trouble using it by not knowing what record a
  998. field
  999. belongs to.  I usually use it only when a line of code becomes too
  1000. long.
  1001.  
  1002. Daniel W. Rickey
  1003. drickey@.irus.rri.uwo.ca
  1004.  
  1005. Imaging Research Laboratories
  1006. The J.P. Robarts Research Institute
  1007. 100 Perth Drive
  1008. London, Ontario
  1009. CANADA  N6A 5K8
  1010.  
  1011. +++++++++++++++++++++++++++
  1012.  
  1013. >From casgrain@ERE.UMontreal.CA (Casgrain Philippe)
  1014. Date: Thu, 24 Feb 1994 16:25:05 GMT
  1015. Organization: Universite de Montreal
  1016.  
  1017. drickey@irus.rri.uwo.ca (Daniel W. Rickey) writes:
  1018.  
  1019. >>In article <2kh51i$50q@ncrpda.curtin.edu.au>
  1020. >>peter@ncrpda.curtin.edu.au (Peter N Lewis) writes:
  1021. >> I will say that not using the WITH statement is a good idea.  The WITH
  1022. >> statement leads to lots of very subtle errors, and generally should
  1023. >> be avoided.
  1024. >The with satement should not be avoided.  It should, however, be used with
  1025. >care.  One can get in trouble using it by not knowing what record a field
  1026. >belongs to.  I usually use it only when a line of code becomes too long.
  1027.  
  1028. I agree with Peter: what if you use 'with' to de-reference a handle (a 
  1029. common use), and the code between the 'with' and its 'end' moves
  1030. memory? Now that could lead to nasty errors, would'nt it!
  1031.  
  1032. If you want to use the "with" statement, IMHO you better be sure that
  1033. your code does not move memory inside the statement. If you are not sure,
  1034. do not use "with".
  1035.  
  1036. Philippe
  1037. --
  1038. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1039. Philippe Casgrain              Etudiant-Chercheur      Casgrain@ERE.UMontreal.CA
  1040. Departement des Sciences Biologiques                      Universite de Montreal
  1041.                   "Imitation is the sincerest form of flattery"
  1042.  
  1043. +++++++++++++++++++++++++++
  1044.  
  1045. >From cshotton@oac.hsc.uth.tmc.edu (Chuck Shotton)
  1046. Date: Thu, 24 Feb 1994 11:37:20 -0600
  1047. Organization: Academic Computing, UT-Houston
  1048.  
  1049. In article <lemieuse.762107105@alize.ERE.UMontreal.CA>,
  1050. casgrain@ERE.UMontreal.CA (Casgrain Philippe) wrote:
  1051.  
  1052. > drickey@irus.rri.uwo.ca (Daniel W. Rickey) writes:
  1053. > >>In article <2kh51i$50q@ncrpda.curtin.edu.au>
  1054. > >>peter@ncrpda.curtin.edu.au (Peter N Lewis) writes:
  1055. > >> I will say that not using the WITH statement is a good idea.  The WITH
  1056. > >> statement leads to lots of very subtle errors, and generally should
  1057. > >> be avoided.
  1058. > >The with satement should not be avoided.  It should, however, be used with
  1059. > >care.  One can get in trouble using it by not knowing what record a field
  1060. > >belongs to.  I usually use it only when a line of code becomes too long.
  1061. > I agree with Peter: what if you use 'with' to de-reference a handle (a 
  1062. > common use), and the code between the 'with' and its 'end' moves
  1063. > memory? Now that could lead to nasty errors, would'nt it!
  1064. > If you want to use the "with" statement, IMHO you better be sure that
  1065. > your code does not move memory inside the statement. If you are not sure,
  1066. > do not use "with".
  1067.  
  1068. Code moving memory has nothing to do with the "safety" of a with statement.
  1069. "With" is a compile-time construct that allows a shorthand notation to be
  1070. used for complex record references. The COMPILER uses the identifier
  1071. specified in the with statement, coupled with the offsets of fields within
  1072. the record to generate  references for the record fields you refer to in
  1073. the body of the with statement. 
  1074.  
  1075. It has ABSOLUTELY nothing to do with what happens at runtime. It is merely
  1076. a shorthand convenience for the author of Pascal code to use. The same code
  1077. is generated whether a with statement or fully qualified record reference
  1078. is used.
  1079.  
  1080. The single biggest problem I have with the with statement is that it makes
  1081. porting Pascal code to some other language a real pain if you are trying to
  1082. automate the conversion. Not to mention the obvious readability
  1083. problems....
  1084.  
  1085. --_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
  1086. Chuck Shotton                             \ 
  1087. Assistant Director, Academic Computing     \   "Are we there yet?"
  1088. U. of Texas Health Science Center Houston   \ 
  1089. cshotton@oac.hsc.uth.tmc.edu  (713) 794-5650 \ 
  1090. _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-\-_-_-_-_-_-_-_-_-_-_-_-_-
  1091.  
  1092. +++++++++++++++++++++++++++
  1093.  
  1094. >From casgrain@ERE.UMontreal.CA (Casgrain Philippe)
  1095. Date: Thu, 24 Feb 1994 19:38:38 GMT
  1096. Organization: Universite de Montreal
  1097.  
  1098. cshotton@oac.hsc.uth.tmc.edu (Chuck Shotton) writes:
  1099. >Code moving memory has nothing to do with the "safety" of a with statement.
  1100. That's not what Scott Knaster says (in "How to write Macintosh Software, 3rd
  1101. edition). This book is the origin of my remarks.
  1102.  
  1103. Knaster used MPW Pascal, and I re-did his examples with MPW and THINK, and
  1104. you will be surprised to know that a "with" statement actually de-references
  1105. the handle/pointer/whatever in the compiled code. Hence the "may move
  1106. memory" warning.
  1107.  
  1108. If you want, I will be happy to fish out the exact quotation for you.
  1109.  
  1110. Philippe
  1111.  
  1112. B
  1113. >"With" is a compile-time construct that allows a shorthand notation to be
  1114. B
  1115. >used for complex record references. The COMPILER uses the identifier
  1116. >specified in the with statement, coupled with the offsets of fields within
  1117. >the record to generate  references for the record fields you refer to in
  1118. >the body of the with statement. 
  1119.  
  1120. >It has ABSOLUTELY nothing to do with what happens at runtime. It is merely
  1121. >a shorthand convenience for the author of Pascal code to use. The same code
  1122. >is generated whether a with statement or fully qualified record reference
  1123. >is used.
  1124.  
  1125. >The single biggest problem I have with the with statement is that it makes
  1126. >porting Pascal code to some other language a real pain if you are trying to
  1127. >automate the conversion. Not to mention the obvious readability
  1128. >problems....
  1129.  
  1130. >--_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
  1131. >Chuck Shotton                             \ 
  1132. >Assistant Director, Academic Computing     \   "Are we there yet?"
  1133. >U. of Texas Health Science Center Houston   \ 
  1134. >cshotton@oac.hsc.uth.tmc.edu  (713) 794-5650 \ 
  1135. >_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-\-_-_-_-_-_-_-_-_-_-_-_-_-
  1136. --
  1137. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1138. Philippe Casgrain              Etudiant-Chercheur      Casgrain@ERE.UMontreal.CA
  1139. Departement des Sciences Biologiques                      Universite de Montreal
  1140.                   "Imitation is the sincerest form of flattery"
  1141.  
  1142. +++++++++++++++++++++++++++
  1143.  
  1144. >From lylem@vax.sonoma.edu (Michael R. Lyle)
  1145. Date: Thu, 24 Feb 1994 13:00:33 -0800
  1146. Organization: Sonoma State University
  1147.  
  1148. > B
  1149. > >"With" is a compile-time construct that allows a shorthand notation to be
  1150. > B
  1151. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1152. > Philippe Casgrain              Etudiant-Chercheur      Casgrain@ERE.UMontreal.CA
  1153. > Departement des Sciences Biologiques                      Universite de Montreal
  1154. >                   "Imitation is the sincerest form of flattery"
  1155.  
  1156. Please note that the Pascal _STANDARD_ says that _with_ is executable.  The
  1157. orignal (Wirth) documents implied that it was only syntactic sugar, but all
  1158. implementations made it executable, so the standard was changed in about
  1159. 1981.
  1160.  
  1161. Note:  This means that once you have done _with_ on any data item, its
  1162. address is probably in a register and that address will be used to
  1163. reference it from then until the end of the scope of the _with_ statement. 
  1164. If the actual data item moves, your reference may well be invalid.
  1165.  
  1166. >From an old Pascal teacher who still prefers it to C and C++....
  1167. -- 
  1168. Michael R. Lyle
  1169. Sonoma State University
  1170. Rohnert Park, CA 94928
  1171. lylem@sonoma.edu
  1172.  
  1173. +++++++++++++++++++++++++++
  1174.  
  1175. >From siegel@netcom.com (Rich Siegel)
  1176. Date: Fri, 25 Feb 1994 01:44:43 GMT
  1177. Organization: Bare Bones Software
  1178.  
  1179. In article <cshotton-240294113720@oac2.hsc.uth.tmc.edu> cshotton@oac.hsc.uth.tmc.edu (Chuck Shotton) writes:
  1180. >
  1181. >Code moving memory has nothing to do with the "safety" of a with statement.
  1182. >"With" is a compile-time construct that allows a shorthand notation to be
  1183. >used for complex record references. The COMPILER uses the identifier
  1184. >specified in the with statement, coupled with the offsets of fields within
  1185. >the record to generate  references for the record fields you refer to in
  1186. >the body of the with statement. 
  1187. >
  1188. >It has ABSOLUTELY nothing to do with what happens at runtime. It is merely
  1189. >a shorthand convenience for the author of Pascal code to use. The same code
  1190. >is generated whether a with statement or fully qualified record reference
  1191. >is used.
  1192.  
  1193. Oh, you think so, do you? :-)
  1194.  
  1195. Here is a simple counter-example.
  1196.  
  1197. Given this Pascal code:
  1198.  
  1199. program Main;
  1200.  
  1201.  type
  1202.   RecordType = record
  1203.     fieldA: Integer;
  1204.     fieldB: Integer;
  1205.    end;
  1206.   RecordPtr = ^RecordType;
  1207.   RecordHandle = ^RecordPtr;
  1208.  
  1209.  procedure P (r: RecordHandle);
  1210.  begin
  1211.   with r^^ do
  1212.    begin
  1213.     fieldA := 10;
  1214.     fieldB := 20;
  1215.    end;
  1216.  end;
  1217.  
  1218.  procedure Q (r: RecordHandle);
  1219.  begin
  1220.   r^^.fieldA := 20;
  1221.   r^^.fieldB := 40;
  1222.  end;
  1223.  
  1224.  var
  1225.   r: RecordHandle;
  1226.  
  1227. begin
  1228.  r := RecordHandle(NewHandle(SizeOf(RecordType)));
  1229.  p(r);
  1230.  q(r);
  1231. end.
  1232.  
  1233. THINK Pascal 2.0 and later will generate the following code for P and
  1234. Q, respectively:
  1235.  
  1236.   P
  1237.      +0000    *LINK       A6,#$0000
  1238.      +0004     MOVE.L     A4,-(A7)
  1239.      +0006     MOVEA.L    $0008(A6),A0
  1240.      +000A     MOVEA.L    (A0),A4
  1241.      +000C     MOVE.W     #$000A,(A4)
  1242.      +0010     MOVE.W     #$0014,$0002(A4)
  1243.      +0016     MOVEA.L    (A7)+,A4
  1244.      +0018     UNLK       A6
  1245.      +001A     MOVE.L     (A7)+,(A7)
  1246.      +001C     RTS
  1247.      
  1248.   Q
  1249.      +0000     LINK       A6,#$0000
  1250.      +0004     MOVEA.L    $0008(A6),A0
  1251.      +0008     MOVEA.L    (A0),A0
  1252.      +000A     MOVE.W     #$0014,(A0)
  1253.      +000E     MOVEA.L    $0008(A6),A0
  1254.      +0012     MOVEA.L    (A0),A0
  1255.      +0014     MOVE.W     #$0028,$0002(A0)
  1256.      +001A     UNLK       A6
  1257.      +001C     MOVE.L     (A7)+,(A7)
  1258.      +001E     RTS
  1259.  
  1260. Note that in P, the generated code places p^ into a register (a4 in this
  1261. case), and then stores relative to the register.
  1262.  
  1263. In Q, p^ is repeatedly generated into a temp (a0, in this case) which
  1264. is then used to store.
  1265.  
  1266. The WITH-clause is not a simple syntactic shorthand. The compiler is
  1267. free to use the presence of a WITH-clause as a hint to the code
  1268. generator to generate more efficient code, and most 68K Pascal
  1269. compilers I've seen avail themselves of this hint.
  1270.  
  1271. R.
  1272.  
  1273. -- 
  1274. Rich Siegel % siegel@netcom.com    % Principal, Bare Bones Software
  1275. --> For information about BBEdit, finger bbedit@world.std.com <--
  1276.  
  1277. "He then proceeded to give a history of the universe, in real time."
  1278.  
  1279. +++++++++++++++++++++++++++
  1280.  
  1281. >From drickey@irus.rri.uwo.ca (Daniel W. Rickey)
  1282. Date: 25 Feb 1994 15:21:20 GMT
  1283. Organization: Imaging Research Labs
  1284.  
  1285. In article <siegelCLrBIn.Cou@netcom.com>
  1286. siegel@netcom.com (Rich Siegel) writes:
  1287.  
  1288. > The WITH-clause is not a simple syntactic shorthand. The compiler is
  1289. > free to use the presence of a WITH-clause as a hint to the code
  1290. > generator to generate more efficient code, and most 68K Pascal
  1291. > compilers I've seen avail themselves of this hint.
  1292. > R.
  1293. > -- 
  1294. > Rich Siegel % siegel@netcom.com        % Principal, Bare Bones Software
  1295.  
  1296.  
  1297. Well, one learns something new everyday.  I too thought the with
  1298. statement did not affect the code generation.  Does this mean that we
  1299. should never use a With statement to dereference a handle?  I tend to
  1300. use the With statement only to dereference pointers.
  1301.  
  1302. Daniel W. Rickey
  1303. drickey@.irus.rri.uwo.ca
  1304.  
  1305. Imaging Research Laboratories
  1306. The J.P. Robarts Research Institute
  1307. 100 Perth Drive
  1308. London, Ontario
  1309. CANADA  N6A 5K8
  1310.  
  1311. +++++++++++++++++++++++++++
  1312.  
  1313. >From pottier@galion.ens.fr (Francois Pottier)
  1314. Date: 25 Feb 1994 16:27:09 GMT
  1315. Organization: Ecole Normale Superieure, PARIS, France
  1316.  
  1317. In article <2kh51i$50q@ncrpda.curtin.edu.au>,
  1318. Peter N Lewis <peter@ncrpda.curtin.edu.au> wrote:
  1319.  
  1320. >I will say that not using the WITH statement is a good idea.  The WITH
  1321. >statement leads to lots of very subtle errors, and generally should
  1322. >be avoided.
  1323.  
  1324. Well, I beg to differ. I'd rather say: the Mac Memory Manager leads to lots
  1325. of very subtle errors, and you should generally avoid using
  1326.   with theHandle do
  1327. or
  1328.   with theObject do
  1329. constructs, unless you are certain not to move memory.
  1330.  
  1331. Also, OOP can be dangerous. Since every method contains a implicit
  1332. "with Self do" construct, moving memory could move your object from under you.
  1333.  
  1334. If you know about those pitfalls and carefully avoid them, there is nothing
  1335. wrong with the with construct... For instance, when filling a parameter
  1336. block, using a with construct is much more elegant than the C way:
  1337.  
  1338. paramBlock.ioVRefNum = ...
  1339. paramBlock.ioDirID = ...
  1340.  
  1341. which is very redundant.
  1342.  
  1343. Cheers,
  1344.  
  1345. -- 
  1346. Francois Pottier            ___ ___  _    _  / ___  ___    ___
  1347. pottier@dmi.ens.fr       /_  /__/ /_|  /| / /  / /  / / /__
  1348.               /   / \  /  | / |/ /___ /__/ / ___/ _
  1349.                           /
  1350.  
  1351. +++++++++++++++++++++++++++
  1352.  
  1353. >From mxmora@unix.sri.com (Matt Mora)
  1354. Date: 25 Feb 1994 08:27:47 -0800
  1355. Organization: SRI International, Menlo Park, CA
  1356.  
  1357. In article <2kl51g$9hb@falcon.ccs.uwo.ca> drickey@irus.rri.uwo.ca (Daniel W. Rickey) writes:
  1358. >In article <siegelCLrBIn.Cou@netcom.com>
  1359. >siegel@netcom.com (Rich Siegel) writes:
  1360.  
  1361. >> The WITH-clause is not a simple syntactic shorthand. The compiler is
  1362. >> free to use the presence of a WITH-clause as a hint to the code
  1363. >> generator to generate more efficient code, and most 68K Pascal
  1364. >> compilers I've seen avail themselves of this hint.
  1365.  
  1366. >Well, one learns something new everyday.  I too thought the with
  1367. >statement did not affect the code generation.  Does this mean that we
  1368. >should never use a With statement to dereference a handle?  I tend to
  1369. >use the With statement only to dereference pointers.
  1370.  
  1371.  
  1372. Works with handles just fine. Just lock them first. I was supprised to see
  1373. Peter bash this cool feature of Pascal. I was told that features like
  1374. this help Pascal compilers optimize code better than c ever could.
  1375.  
  1376. Xavier
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.  
  1384. -- 
  1385. ___________________________________________________________
  1386. Matthew Xavier Mora                    Matt_Mora@qm.sri.com
  1387. SRI International                       mxmora@unix.sri.com
  1388. 333 Ravenswood Ave                    Menlo Park, CA. 94025
  1389.  
  1390. +++++++++++++++++++++++++++
  1391.  
  1392. >From casgrain@ERE.UMontreal.CA (Casgrain Philippe)
  1393. Date: Fri, 25 Feb 1994 19:24:45 GMT
  1394. Organization: Universite de Montreal
  1395.  
  1396. pottier@galion.ens.fr (Francois Pottier) writes:
  1397.  
  1398. >Well, I beg to differ. I'd rather say: the Mac Memory Manager leads to lots
  1399. >of very subtle errors, and you should generally avoid using
  1400. >  with theHandle do
  1401. >or
  1402. >  with theObject do
  1403. >constructs, unless you are certain not to move memory.
  1404.  
  1405. Well ;-> if you are not certain about the moving memory stuff (some 
  1406. toolbox calls move memory indirectly, by calling other toolbox calls that
  1407. themselves move memory), you can always lock your handles before the
  1408. "with" (HLock) and unlock them after (HUnlock). Be careful not to leave
  1409. your handles locked for too long, as your heap will become fragmented.
  1410.  
  1411. On a related note, the TB calls that move memory usually are documented
  1412. as such (for example, there's the little "memory chip" icon in THINK
  1413. Reference), but there are probably some errors and omissions, although I
  1414. can't think of any offhand. Anyone? Anyone?
  1415.  
  1416. Philippe
  1417. --
  1418. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  1419. Philippe Casgrain              Etudiant-Chercheur      Casgrain@ERE.UMontreal.CA
  1420. Departement des Sciences Biologiques                      Universite de Montreal
  1421.                   "Imitation is the sincerest form of flattery"
  1422.  
  1423. +++++++++++++++++++++++++++
  1424.  
  1425. >From siegel@netcom.com (Rich Siegel)
  1426. Date: Fri, 25 Feb 1994 20:20:44 GMT
  1427. Organization: Bare Bones Software
  1428.  
  1429. In article <2kl51g$9hb@falcon.ccs.uwo.ca> drickey@irus.rri.uwo.ca (Daniel W. Rickey) writes:
  1430. >
  1431. >Well, one learns something new everyday.  I too thought the with
  1432. >statement did not affect the code generation.  Does this mean that we
  1433. >should never use a With statement to dereference a handle?  I tend to
  1434. >use the With statement only to dereference pointers.
  1435.  
  1436. "never" is a little strong. Use it any way you like, but just be aware
  1437. of the implications when you do.
  1438.  
  1439. R.
  1440.  
  1441. -- 
  1442. Rich Siegel % siegel@netcom.com    % Principal, Bare Bones Software
  1443. --> For information about BBEdit, finger bbedit@world.std.com <--
  1444.  
  1445. "He then proceeded to give a history of the universe, in real time."
  1446.  
  1447. +++++++++++++++++++++++++++
  1448.  
  1449. >From cshotton@oac.hsc.uth.tmc.edu (Chuck Shotton)
  1450. Date: Fri, 25 Feb 1994 19:43:38 -0600
  1451. Organization: UT Houston Academic Computing
  1452.  
  1453. In article <siegelCLrBIn.Cou@netcom.com>, siegel@netcom.com (Rich Siegel)
  1454. wrote:
  1455.  
  1456. > In article <cshotton-240294113720@oac2.hsc.uth.tmc.edu> cshotton@oac.hsc.uth.tmc.edu (Chuck Shotton) writes:
  1457. > Oh, you think so, do you? :-)
  1458. > Here is a simple counter-example.
  1459. > [code snipped]
  1460. > The WITH-clause is not a simple syntactic shorthand. The compiler is
  1461. > free to use the presence of a WITH-clause as a hint to the code
  1462. > generator to generate more efficient code, and most 68K Pascal
  1463. > compilers I've seen avail themselves of this hint.
  1464.  
  1465. You are correct. Mac compiler writers have implemented the "with" in a
  1466. non-safe fashion. The Jensen & Wirth book never indicates how code is to be
  1467. generated for this statement, but very clearly identifies it as a syntactic
  1468. short cut rather than a cue to the code generator. To me, that should
  1469. indicate that the non-safe code generated by Mac compilers when
  1470. dereferenced pointers and handles are "withed" is not exactly compliant
  1471. with the standard.
  1472.  
  1473. -----------------------------------------------------------------------
  1474. Chuck Shotton
  1475. cshotton@oac.hsc.uth.tmc.edu                           "I am NOT here."
  1476.  
  1477. +++++++++++++++++++++++++++
  1478.  
  1479. >From peter@ncrpda.curtin.edu.au (Peter N Lewis)
  1480. Date: 27 Feb 1994 12:46:09 +0800
  1481. Organization: NCRPDA, Curtin University
  1482.  
  1483. mxmora@unix.sri.com (Matt Mora) writes:
  1484.  
  1485. >Works with handles just fine. Just lock them first. I was supprised to see
  1486. >Peter bash this cool feature of Pascal. I was told that features like
  1487. >this help Pascal compilers optimize code better than c ever could.
  1488.  
  1489. True, that and for loops and generally many fewer pointers (pointers confuse
  1490. the heck out of optimizers in general).
  1491.  
  1492. The with statement has its place, but it must be used very causiously.  It
  1493. can cause problems if you do "with h^" and the handle moves inside the with
  1494. statement.  It can cause problems if you "with rec", and rec contains fields
  1495. that clash with global or local variables (this is especially painful when
  1496. global or local variables clash with object variables, since THINK Pascal
  1497. puts in a "with self" implicitly).  It's also interesting to note that most
  1498. compilers won't generate less efficient code for these two:
  1499.  
  1500. pb.a := 1;
  1501. pb.b := 2;
  1502. ..
  1503.  
  1504. as compared with
  1505.  
  1506. with pb do begin
  1507.   a := 1;
  1508.   b := 2;
  1509.   ...
  1510. end;
  1511.  
  1512. In any event, my advice, especially to beginning programmers is to 
  1513. avoid the with statement as a general rule until you really understand
  1514. what it does and what its dangers are.  Of course, you can't avoid the
  1515. implicit "with self", so you better learn about those dangers pretty quick!
  1516.    Peter.
  1517. -- 
  1518. Peter N Lewis <peter.lewis@info.curtin.edu.au>       Ph: +61 9 368 2055
  1519.  
  1520. +++++++++++++++++++++++++++
  1521.  
  1522. >From peter@ncrpda.curtin.edu.au (Peter N Lewis)
  1523. Date: 27 Feb 1994 12:49:57 +0800
  1524. Organization: NCRPDA, Curtin University
  1525.  
  1526. casgrain@ERE.UMontreal.CA (Casgrain Philippe) writes:
  1527.  
  1528. >On a related note, the TB calls that move memory usually are documented
  1529. >as such (for example, there's the little "memory chip" icon in THINK
  1530. >Reference), but there are probably some errors and omissions, although I
  1531. >can't think of any offhand. Anyone? Anyone?
  1532.  
  1533. My policy is to assume everything can move memory except BlockMove, 
  1534. PBRead and PBWrite (and FSRead and FSWrite).  As a general rule, they
  1535. are the only common routines that you use with handle data that are
  1536. handle-safe.  Remember that you aren't only dealing with what the OS does
  1537. now, but also what it might do in the future (witness SysBeep), and
  1538. also what broken inits (like some from Apple! ;-) that change the
  1539. memory-safeness of routines.
  1540.    Peter.
  1541. -- 
  1542. Peter N Lewis <peter.lewis@info.curtin.edu.au>       Ph: +61 9 368 2055
  1543.  
  1544. +++++++++++++++++++++++++++
  1545.  
  1546. >From quinn@uniwa.uwa.edu.au (Quinn "The Eskimo!")
  1547. Date: 27 Feb 1994 13:29:06 +0800
  1548. Organization: The University of Western Australia
  1549.  
  1550. mxmora@unix.sri.com (Matt Mora) writes:
  1551.  
  1552. >[...] I was supprised to see
  1553. >Peter bash this cool feature of Pascal. I was told that features like
  1554. >this help Pascal compilers optimize code better than c ever could.
  1555.  
  1556. But Pete uses Pascal because it's safer, not because it produces better
  1557. code.  The with statement is wildly unsafe because it brings identifiers
  1558. into scope with very little warning.  [In that respect it's very like
  1559. Pascal's uses clause which is also braindead, especially wehn compared
  1560. to Modula 2's import/export mechanism.]
  1561.  
  1562. What I'd like to see is the with statement redone so that it doesn't
  1563. introduce new identifiers invisibly.  For example instead of doing
  1564. this...
  1565.  
  1566.   with graf_ptr^.pnLoc do begin
  1567.     frog := h;
  1568.   end; (* with *)
  1569.  
  1570. you get something more like this...
  1571.  
  1572.   with my_pn_loc ::= graf_ptr^.pnLoc do
  1573.     frog := my_pn_loc.h;
  1574.   end-with;
  1575.  
  1576. The second version introduces a name for the temporary result, which
  1577. you then use in a qualified fashion.  Much safer IMHO.
  1578.  
  1579. --
  1580. Quinn "The Eskimo!"      <quinn@cs.uwa.edu.au>     "Support HAVOC!"
  1581. Department of Computer Science, The University of Western Australia
  1582.   I hate unix!!!  I hate nn!!!  I wan't my static IP number back ):
  1583. -- 
  1584.  
  1585. Quinn "The Eskimo!"      <quinn@cs.uwa.edu.au>     "Support HAVOC!"
  1586. Department of Computer Science, The University of Western Australia
  1587.   I hate unix!!!
  1588.  
  1589. +++++++++++++++++++++++++++
  1590.  
  1591. >From peter@ncrpda.curtin.edu.au (Peter N Lewis)
  1592. Date: 28 Feb 1994 11:25:24 +0800
  1593. Organization: NCRPDA, Curtin University
  1594.  
  1595. cshotton@oac.hsc.uth.tmc.edu (Chuck Shotton) writes:
  1596.  
  1597. >You are correct. Mac compiler writers have implemented the "with" in a
  1598.  
  1599. It's not just Mac compilers, it's how every compiler I've ever seen (and
  1600. indeed every compiler I've ever written!) has implemented the with statement.
  1601. If thats not part of the standard, then it's the standard that is wrong.
  1602. But the fact is that it doesn't matter which way it's implemented, this
  1603. would still be dangerous:
  1604.  
  1605. with p^ do begin
  1606.   Dispose(p);
  1607.   x := 5;
  1608. end;
  1609.  
  1610. Where x is a local variable and a field of p^.  The only reason it is
  1611. unsafe with handles is because of the Mac's treatment of handles as
  1612. movable.  But it would still be unsafe under other OSes if other conditions
  1613. like the above happened.
  1614.    Peter.
  1615. -- 
  1616. Peter N Lewis <peter.lewis@info.curtin.edu.au>       Ph: +61 9 368 2055
  1617.  
  1618. +++++++++++++++++++++++++++
  1619.  
  1620. >From D.A.G.Gillies@bradford.ac.uk (DAG GILLIES)
  1621. Date: Mon, 28 Feb 1994 13:28:18 GMT
  1622. Organization: University of Bradford, UK
  1623.  
  1624. In article <2kl8u3$ao@unix.sri.com> mxmora@unix.sri.com (Matt Mora) writes:
  1625. >In article <2kl51g$9hb@falcon.ccs.uwo.ca> drickey@irus.rri.uwo.ca (Daniel W. Rickey) writes:
  1626. >>In article <siegelCLrBIn.Cou@netcom.com>
  1627. >>siegel@netcom.com (Rich Siegel) writes:
  1628. >
  1629. >>> The WITH-clause is not a simple syntactic shorthand. The compiler is
  1630. >>> free to use the presence of a WITH-clause as a hint to the code
  1631. >>> generator to generate more efficient code, and most 68K Pascal
  1632. >>> compilers I've seen avail themselves of this hint.
  1633. >
  1634. >>Well, one learns something new everyday.  I too thought the with
  1635. >>statement did not affect the code generation.  Does this mean that we
  1636. >>should never use a With statement to dereference a handle?  I tend to
  1637. >>use the With statement only to dereference pointers.
  1638. >
  1639. >
  1640. >Works with handles just fine. Just lock them first. I was supprised to see
  1641. >Peter bash this cool feature of Pascal. I was told that features like
  1642. >this help Pascal compilers optimize code better than c ever could.
  1643. >
  1644.  
  1645. Am I missing something here, or am I mistaken when I recall that in the first
  1646. few pages of Volume I of (old) Inside Mac, there is a specific warning
  1647. about locking handles before dereferencing them, and that the Pascal WITH
  1648. statement can cause an implicit dereference. There was a code fragment
  1649. along the lines of
  1650.  
  1651. HLock(aHandle)
  1652.  
  1653. WITH aHandle DO
  1654.     ...
  1655.     ...
  1656.     ...
  1657.  
  1658. HUnlock(aHandle)
  1659.  
  1660.  
  1661. I mean, if it's in IM, why all the controversy?
  1662.  
  1663.  
  1664. ______________________________________________________
  1665. David A. G. Gillies     (D.A.G.Gillies@bradford.ac.uk)
  1666. (c) 1994 Wittgenstein's Amazing Underwater Supermarket
  1667.  
  1668. ---------------REPLIES VIA EMAIL PLEASE---------------
  1669. _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  1670.  
  1671. +++++++++++++++++++++++++++
  1672.  
  1673. >From neeri@iis.ee.ethz.ch (Matthias Neeracher)
  1674. Date: 28 Feb 94 17:38:00
  1675. Organization: Integrated Systems Laboratory, ETH, Zurich
  1676.  
  1677. In article <cshotton-250294194338@oacslip202.hsc.uth.tmc.edu>, cshotton@oac.hsc.uth.tmc.edu (Chuck Shotton) writes:
  1678.  
  1679. > In article <siegelCLrBIn.Cou@netcom.com>, siegel@netcom.com (Rich Siegel)
  1680. > wrote:
  1681. >> The WITH-clause is not a simple syntactic shorthand. The compiler is
  1682. >> free to use the presence of a WITH-clause as a hint to the code
  1683. >> generator to generate more efficient code, and most 68K Pascal
  1684. >> compilers I've seen avail themselves of this hint.
  1685.  
  1686. > You are correct. Mac compiler writers have implemented the "with" in a
  1687. > non-safe fashion. The Jensen & Wirth book never indicates how code is to be
  1688. > generated for this statement, but very clearly identifies it as a syntactic
  1689. > short cut rather than a cue to the code generator. To me, that should
  1690. > indicate that the non-safe code generated by Mac compilers when
  1691. > dereferenced pointers and handles are "withed" is not exactly compliant
  1692. > with the standard.
  1693.  
  1694. A few comments:
  1695.  
  1696.  - Jensen & Wirth is not the Pascal Standard.
  1697.  - At least one ETH Modula-2 compiler, which certainly was authorized by Wirth,
  1698.    does no register allocation except to use two of the address registers
  1699.    for the two innermost WITH statements.
  1700.  - I would suspect that something similar was done for many Pascal compilers.
  1701.  - The reason why this is not mentioned is probably that J&W were not concerned
  1702.    with such problems, and indeed, this problem is not very important outside
  1703.    of a handle based environment.
  1704.  
  1705. Matthias
  1706.  
  1707. -----
  1708. Matthias Neeracher                                neeri@iis.ee.ethz.ch
  1709.    "One fine day in my odd past..." -- Pixies, _Planet of Sound_
  1710.  
  1711. +++++++++++++++++++++++++++
  1712.  
  1713. >From peirce@outpost.SF-Bay.org (Michael Peirce)
  1714. Date: Mon, 28 Feb 94 10:42:19 PST
  1715. Organization: Peirce Software, Inc.
  1716.  
  1717.  
  1718. In article <cshotton-250294194338@oacslip202.hsc.uth.tmc.edu> (comp.sys.mac.programmer), cshotton@oac.hsc.uth.tmc.edu (Chuck Shotton) writes:
  1719. > In article <siegelCLrBIn.Cou@netcom.com>, siegel@netcom.com (Rich Siegel)
  1720. > wrote:
  1721. > > In article <cshotton-240294113720@oac2.hsc.uth.tmc.edu> cshotton@oac.hsc.uth.tmc.edu (Chuck Shotton) writes:
  1722. > > 
  1723. > > Oh, you think so, do you? :-)
  1724. > > 
  1725. > > Here is a simple counter-example.
  1726. > > [code snipped]
  1727. > > The WITH-clause is not a simple syntactic shorthand. The compiler is
  1728. > > free to use the presence of a WITH-clause as a hint to the code
  1729. > > generator to generate more efficient code, and most 68K Pascal
  1730. > > compilers I've seen avail themselves of this hint.
  1731. > You are correct. Mac compiler writers have implemented the "with" in a
  1732. > non-safe fashion. The Jensen & Wirth book never indicates how code is to be
  1733. > generated for this statement, but very clearly identifies it as a syntactic
  1734. > short cut rather than a cue to the code generator. To me, that should
  1735. > indicate that the non-safe code generated by Mac compilers when
  1736. > dereferenced pointers and handles are "withed" is not exactly compliant
  1737. > with the standard.
  1738.  
  1739. Don't blame just Mac Pascal compilers.  I know of at least one PDP-11
  1740. Pascal compiler that does this same thing.  I expect there are others.
  1741. (I think the VAX Pascal compiler did this too)
  1742.  
  1743. Frankly, I wish there was a similar construct in c - or at least C
  1744. compilers that were smart enough to dereference a struct into a register
  1745. instead of constantly redereferencing.  The Pascal code is much more
  1746. efficient in this case.  (A good example of this is filling in a BIG
  1747. parameter block).
  1748.  
  1749.  
  1750. -- Michael Peirce        -- peirce@outpost.sf-bay.org
  1751. -- Peirce Software, Inc. -- 719 Hibiscus Place, Suite 301
  1752. --                       -- San Jose, California USA 95117
  1753. -- Makers of: Smoothie & -- voice: +1.408.244.6554 fax: +1.408.244.6882
  1754. --    Peirce Print Tools -- AppleLink: peirce & America Online: AFC Peirce
  1755.  
  1756. +++++++++++++++++++++++++++
  1757.  
  1758. >From platypus@cirrus.som.cwru.edu (Gary Kacmarcik)
  1759. Date: 02 Mar 1994 01:01:15 GMT
  1760. Organization: Case Western Reserve University, Cleveland, Ohio (USA)
  1761.  
  1762. In article <CNjbKKKX.peuobu@outpost.SF-Bay.org> peirce@outpost.SF-Bay.org (Michael Peirce) writes:
  1763. > In article <cshotton-250294194338@oacslip202.hsc.uth.tmc.edu> (comp.sys.mac.programmer), cshotton@oac.hsc.uth.tmc.edu (Chuck Shotton) writes:
  1764. > > In article <siegelCLrBIn.Cou@netcom.com>, siegel@netcom.com (Rich Siegel)
  1765. > > wrote:
  1766. > > > 
  1767. > > > The WITH-clause is not a simple syntactic shorthand. The compiler is
  1768. > > > free to use the presence of a WITH-clause as a hint to the code
  1769. > > > generator to generate more efficient code, and most 68K Pascal
  1770. > > > compilers I've seen avail themselves of this hint.
  1771. > > 
  1772. > > You are correct. Mac compiler writers have implemented the "with" in a
  1773. > > non-safe fashion. The Jensen & Wirth book never indicates how code is to be
  1774. > > generated for this statement, but very clearly identifies it as a syntactic
  1775. > > short cut rather than a cue to the code generator. To me, that should
  1776. > > indicate that the non-safe code generated by Mac compilers when
  1777. > > dereferenced pointers and handles are "withed" is not exactly compliant
  1778. > > with the standard.
  1779. >
  1780. > Don't blame just Mac Pascal compilers.  I know of at least one PDP-11
  1781. > Pascal compiler that does this same thing.  I expect there are others.
  1782. > (I think the VAX Pascal compiler did this too)
  1783. >
  1784. > Frankly, I wish there was a similar construct in c - or at least C
  1785. > compilers that were smart enough to dereference a struct into a register
  1786. > instead of constantly redereferencing.  The Pascal code is much more
  1787. > efficient in this case.  (A good example of this is filling in a BIG
  1788. > parameter block).
  1789.  
  1790. ummm...
  1791.  
  1792. i don't understand your comment that Pascal is "much more efficient"
  1793. in this case.  without the "with" statement, comparable compilers
  1794. should generate code which is equally "bad".
  1795.  
  1796. if you have the "with" statement in Pascal, then you need to add
  1797. the equivalent in C: which is an assignment statement which saves
  1798. the dereferenced handle/ptr.  again, the code should be comparable.
  1799. (if not, you should get a better compiler ;-)
  1800.  
  1801. C expects you to explicitly store the value in a temp variable, which
  1802. is exactly what the "with" statement (as described above) does.  i
  1803. don't see any real need for a "with" statement - it makes the
  1804. code slightly less explicit and potentially confusing (eg: with
  1805. multiple "with"s into structures that have fields/records with the
  1806. same name).
  1807.  
  1808. being explicit (either in C or Pascal) makes the code more readable:
  1809. i detest reading Pascal code where the programmer uses multiple
  1810. nested "with" statements because it makes it much more difficult to
  1811. identify which struct the field belongs to.
  1812.  
  1813.  
  1814. -gary j kacmarcik
  1815. platypus@curie.ces.cwru.edu
  1816.  
  1817.  
  1818.  
  1819. ---------------------------
  1820.  
  1821. End of C.S.M.P. Digest
  1822. **********************
  1823.  
  1824.  
  1825.