Spin code formatting
Paul Baker
Posts: 6,351
Im posting this because I know there will be many questions raised about programs not working as expected when people start writing Spin programs.
The Spin language requires proper formating, it does this by using indentation. If you have a loop, the code that belongs in that loop must be indented, this is how Spin knows what belongs in the loop.
I suspect there will be some who miss this aspect, in addition to people asking for help with thier code by just cutting and pasting thier program in the post form. Because the standard entry method strips all leading whitespace, it is inevitable that many times we'll have to ask people to repost thier code in proper form to understand what thier code is doing, since the preservation of·indentation is required·in order to·preserve the meaning of the code.
There are three ways to properly post spin code to the forums:
1) post the code as an attachment (perfered for longer programs)
2) post the code in a formatted code·window (the # in the full post dialog)
3)·manually indent (not recomended because this leads to copy errors)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
The Spin language requires proper formating, it does this by using indentation. If you have a loop, the code that belongs in that loop must be indented, this is how Spin knows what belongs in the loop.
I suspect there will be some who miss this aspect, in addition to people asking for help with thier code by just cutting and pasting thier program in the post form. Because the standard entry method strips all leading whitespace, it is inevitable that many times we'll have to ask people to repost thier code in proper form to understand what thier code is doing, since the preservation of·indentation is required·in order to·preserve the meaning of the code.
There are three ways to properly post spin code to the forums:
1) post the code as an attachment (perfered for longer programs)
2) post the code in a formatted code·window (the # in the full post dialog)
3)·manually indent (not recomended because this leads to copy errors)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Comments
Code displayed in this fashion can be copied and pasted into the Propeller IDE or any other text editor, and the original formatting will be recovered.
One caveat: If you edit a post that has formatted code in it, you may need to repaste the formatted code to make it display properly. The reason is that the formatter replaces occurances of [noparse][[/noparse] and ] with their HTML-coded equivalents, [ and ]. But when these are redisplayed in the posting entry window, they show up as [noparse][[/noparse] and ] once again and are entered that way when you hit "SUBMIT".
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
It's not a browser issue, as far as I'm able to tell. The problem is that the [noparse][[/noparse]code] tags don't translate to HTML's <code> or <pre> formatting, but rather to a special CSS DIVision that allows the embedded boldface <b> and italics <i> tags, to which the [noparse][[/noparse]i] and [noparse][[/noparse]b] get translated by the forum software. It would be helpful, I suppose, if the forum code could be fixed to eliminate this possibility. But I've actually been able to use to advantage to highlight Propeller's keywords instead.
-Phil
For the benefit of those of us (like me) who have yet to figure out how this web-based forum business works, could you please expand what you've said below:
2) post the code in a formatted code window (the # in the full post dialog)
I'm guessing you mean DON'T use the Quick Reply feature, which I always do, unfortunately. However, I'm not sure I understand the "#" reference as regards the "full post dialog box", unless you're speaking of the right-most button on the lower-most toolbar in the window which appears when you punch up "Post reply"? .
The reason why I'm not quite sure what that means is that the ONLY way I've found to permit indentations and columnar format in a "Post Reply" window is to use what I saw others using - "slash code" followed by "code slash" - which seems to work most of the time. Thanks in advance for the clarification.
Just in passing, if hard but invisible TABs were universally recognized (both in the forum software and in the Propeller IDE) the problem would be wholly eliminated, as it should be without any ... work-arounds needed by anyone. If there is a problem in using the actual TAB key (as I suspect there may be), some other character configuration would be fine as far as I'm concerned. I can't think of anything that uses or requires the " ` " (AKA single back quotation mark, accent-grave, backprime, or backquote - ASCII decimal 96) just by way of example. Just one person's thoughts.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
Phil, I just can't reproduce the italisized issue when using IE:
a[noparse][[/noparse]i] := text [noparse][[/noparse]/i]
[noparse][[/noparse]i] and [noparse][[/noparse]b] have no effect on my posts, does your browser show any of the above message italisized or bold? I know non-IE browsers do have this effect (when posting).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
No, but when I post it as [noparse][[/noparse]code] it does:
That's weird. What am I doing different?
-Phil
Maybe the carriage returns have en effect?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Martin Hebel
Perform a Survey of Electronic Technology Employers - Click here!
Personal Links with plenty of BASIC Stamp info
and SelmaWare Solutions - StampPlot - Graphical Data Acquisition and Control
Odd..
-MH
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Martin Hebel
Perform a Survey of Electronic Technology Employers - Click here!
Personal Links with plenty of BASIC Stamp info
and SelmaWare Solutions - StampPlot - Graphical Data Acquisition and Control
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
I was wondering too about the "#" button you mentioned, because I don't see that on my form screen. I'm doing this from IE on the Mac, although I usually use Firefox or Safari. This IE form looks the same as the one I see in my other browsers. I'll look at is on a PC later. I am going to paste in some code that includes the special Spin font for drawing circuits. I just want to see if it will come through. I expect it might work okay on a PC that has the Spin font installed, but otherwise it will be garbage. I don't know if Parallax intends to release the font apart from the Propeller package. It is really the cat's meow. If this doesn't look right when I view it on the PC that has the Spin font (is that the corrrect font name?) installed, then I'll delete the code box below and try a different way to paste it in.
Edit: added another attempt at showing spin font.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Post Edited (Tracy Allen) : 3/2/2006 11:43:11 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
-Phil
As a "tool of last resort", I've posted another formatter on my website:
www.phipi.com/format/render.html
Here you can paste Propeller code, and it will create a PNG image of that code, with all the special characters intact and properly spaced. Circuit and waveform diagrams should come out the way you want them to.
Remember: To copy a specific rectangular block from your IDE window, hold down the Alt key while you're selecting the text to copy. That way you can choose which columns to include, thus eliminating the apostrophe(s) at the beginning of the line.
Cheers!
Phil
without me changing any of the default settings. Just a couple of minor spacing issues compared with
the result within the Propeller Tool.
In IE on the PC, it was screwed up. I tried Tools/Internet Options.../General/Fonts and changed both
setting, Tools/Internet Options.../General/Accessibilty to "ignore fonts specified
on web pages", and that made the diode, the resistor and the capacitor display correctly,
but the connecting lines and spacing were still screwed up.
Thanks for the new conversion utility Phil. That's great. I'll try it out.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
In Firefox there were several possible settings for character encoding. I notice that Firefox has set the encoding for this current page at Unicode (UTF-8), and if I set it to anything else (e.g. Western or English), it loses the Parallax font. Firefox must have done that automatically, but I don't know how it picked out the Parallax font. All that is a great mystery to me, and that's why I prefer micros. Messing with these settings seems to stick, and cause problems with other web pages. It sounds like Opera gives you more options.
I tried your PNG renderer, and it did a pretty good job in Firefox, but IE screwed it all up. Once rendered, it is a graphic, right, and it is necessary to upload it as a file to the forum and then link to the graphic. It gets complicated.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
That's why I called it a "tool of last resort".
Yes, once rendered, it's a graphic. You can right click on it and save it to a folder, then upload it to the forum as an image. I doubt anyone'd want to use it for entire program listings but, rather, only for embedded illustrations formed with graphics characters.
I tried it with IE (ver 6.0) and didn't have a problem, but I'm sure earlier versions will make a mess of it. The reason is that the earlier IE versions deferred to the file extension in the URL to determine the file type, rather than using the mime-type sent with the HTTP header. In this case, the mime-type is "image/png", but the file extension is ".pl" (from the Perl CGI program used to generate the image). Over the years, I've wrestled with ways to make this work with IE, but Microsoft seems to have fixed things now, so I didn't bother this time.
Cheers!
Phil
I makes so many things easier to read...
90% of communications are attempts at clarifying the first 10%
[noparse]:)[/noparse]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Just tossing my two bits worth into the bit bucket
KK
·
That is a very kool utility. Good job!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
John J. Couture
San Diego Miramar College
I like the online utility, but I'd rather make a GIF, instead of a PNG. I tried it this way, by pressing Alt-PrintScreen, which puts the image of the current window on the clipboard, then I opened PAINT and pasted in the image, selected the part I wanted, chose "edit/copy to..." saved the selection as a .BMP, then opened the BMP, and then File/saveAs a GIF. That is what I uploaded.
If I were doing this on a Mac, I'd use the "Graphic Converter" utility, but I'm pretty clueless on the PC. There is probably a better program than PAINT. Any ideas about that? It will sure be nice to share the schematics with people who don't have the font.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
I'll give it a try -- later tonite or tomorrow (social obligations are "intruding" just now). I used the GD graphics toolkit add-on to Perl. While the Unisys GIF patent was in force, GD excluded export to GIF files. That patent has now expired, but I'm not sure that the version of GD installed on my webhost's system has been upgraded to include GIF exports again.
I see you changed the foreground and background colors, too. I could probably make this an option...
-Phil
The online formatter does GIFs now, as well as color. The halfscale output is still less than satisfactory, though. It's obtained by downsampling the fullsized raster font in the B/W colorspace (i.e. without anti-aliasing), so it looks pretty ragged. I need to figure out a better template for this scale that looks more natural.
-Phil
On the Mac, shift-command-ctrl-4 brings up a cursor which can be used to select an area on the screen and put it on the clipboard. Then pasted into GraphicConverter, it can be saved in any of 70+ different formats, including either GIF or PNG.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
·· I always use PrintScreen myself.· You can also use ALT-PrintScreen to get just the active window.· In any event pasting into Paint works great for me.· Shrinking it or saving it in a lossy format will affect the picture.· I usually save as a Bitmap and it's perfect.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
I use CorelCapture (which came with CorelDraw) for stuff like that. In fact, that's how I captured the Parallax font matrix used in the online program. But I'm sure there's a plethora of shareware/freeware stuff out there that will do the same thing. When I typed windows screen-capture freeware into Google, I got more than 900,000 hits.
-Phil
Ryan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Ryan Clarke
Parallax Tech Support
RClarke@Parallax.com