Shop OBEX P1 Docs P2 Docs Learn Events
Spin code formatting — Parallax Forums

Spin code formatting

Paul BakerPaul Baker Posts: 6,351
edited 2006-03-06 15:49 in Propeller 1
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

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2006-03-01 20:29
    The code tags are good, but not great, and can sometimes cause errors in the listing. If you have subscripts like [noparse][[/noparse]i&#093, for example, they will be misinterpreted as italics tags and not be displayed. For this reason, I've written a CGI formatting program, available on my website at www.phipi.com/format. Here you can enter or paste your code, click "FORMAT", and you will receive a copy to paste into the forum and that will display properly.

    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, &#091 and &#093. 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
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-03-01 20:32
    You use firefox or some other browser besides IE, right? IE doesn't have the same problems of embedded post formatting.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2006-03-01 20:45
    Hi Paul,

    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
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-03-01 21:10
    Paul -

    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 -->
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-03-01 23:34
    Bruce, Yes Im referring to the button labeled "#" when you are in the form after pressing the "Post Reply" button.

    Phil, I just can't reproduce the italisized issue when using IE:

    a[noparse][[/noparse]i] := text [noparse][[/noparse]/i]

    a[noparse][[/noparse]i] := text [noparse][[/noparse]/i]
    [noparse][[/noparse]b] bold [noparse][[/noparse]/b]
    

    [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
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2006-03-01 23:44
    Hi Paul,

    No, but when I post it as [noparse][[/noparse]code] it does:

    a[i] := text [/i]
    [b] bold [/b]
    



    That's weird. What am I doing different?

    -Phil
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2006-03-01 23:47
    Copying from Email...

    a[i] := text [/i]
    [b] bold [/b]
    



    a[i] := text [/i]
    [b] bold [/b]
    
    



    Maybe the carriage returns have en effect?

    a[i] := text [/i]
    [b] bold [/b]
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2006-03-01 23:48
    Nope, guess not. The top on above was pasted directly from the Email about the post, the 2nd two I put in carriage reurns

    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
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-03-01 23:48
    You are using Internet Explorer? dotNetBB provides two different posting forms, one for IE and one for all other browsers.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2006-03-01 23:53
    I use Opera. 'Wouldn't touch IE! smile.gif Maybe that's the diff, but it's odd that the results wouldn't come out the same, regardless of how it was posted, since everybody has to read it.

    -Phil
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-03-02 16:00
    I think the IE posting form uses ASP or something like that, whatever it is thats used, MS hasn't permitted (or perhaps they dont want) to use the facilities to enable what the IE form does. I use opera as well, but I use IE for the forums because of the different posting form.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2006-03-02 16:57
    Hi Paul,

    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.


    '' -- The following is the circuit diagram rendered in ascii...
    ''
    ''              330       green LED
    ''   a1------/\/\---o--->|-----,                 a1 (+)  ----->|----- (-) a0
    ''                    |  p  n    |                           ------> forward bias
    ''                    |          |                                   lights LED
    ''                   === 220pf   |
    ''                    |          |
    ''   a0--------------o----------'                a1 (-)  ----->|----- (+) a0
    ''                                                           <------ reverse bias
    ''                                                                   discharges capacitor
    ''                                                                rate proportional to light
    ''
    '' -- The following are the same diagrams, rendered in the sweet new Parallax Spin font...
    ''    Find the character chart on the HELP menu.
    ''
    ''        330&#937;  green Led
    ''   a1 &#9472;&#9472;&#9472;&#61629;&#61630;&#9472;&#9472;&#9523;&#9472;&#9472;&#9472;&#61606;&#61607;&#9472;&#9472;&#9472;&#9472;&#9488;                        a1 (+)  &#9472;&#9472;&#9472;&#9472;&#9472;&#61606;&#61607;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;  (-) a0
    ''             &#9474;         &#9474;                                  I &#9472;&#9472;&#9472;&#9472;&#61627;
    ''             &#9507;&#9472;&#9472;&#9472;&#61611;&#9472;&#9472;&#9472;&#9472;&#9472;&#9515;
    ''             &#9474;  220pf  &#9474;
    ''   a0 &#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9524;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9496;                         a1 (-) &#9472;&#9472;&#9472;&#9472;&#9472;&#61606;&#61607;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;   (+) a0 
    ''                                                           &#61626;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472; I
    ''
    



    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
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-03-02 17:53
    I'll have to look at the forums with Opera to check what the equivalent button in alternate browsers are, but I was refering to the code box you used in your post. I haven't tested whether the unicode characters are displayable in a non-IDE program on a computer which has the characters defined, but I know they show up as something else when reading them on a computer which doesn't have the propeller IDE installed.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2006-03-02 18:19
    In Opera, under Tools->Preferences->Advanced->Fonts, scroll down to "CSS font-family monospace". Select the font "Parallax" instead of the default. Now, at least, the special electronics characters will be displayed; but on my system the spacing isn't quite right, and there are gaps between the lines.

    -Phil
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2006-03-02 23:11
    Hi All,

    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
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2006-03-02 23:25
    PC with Firefox, it displayed the Parallax font with the schematic symbols almost perfectly,
    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
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2006-03-03 00:01
    Hi Phil,

    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
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2006-03-03 00:54
    Hi Tracy,

    That's why I called it a "tool of last resort". smile.gif

    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
  • Kaos KiddKaos Kidd Posts: 614
    edited 2006-03-03 15:35
    I love that font...
    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
    ·
  • John CoutureJohn Couture Posts: 370
    edited 2006-03-04 00:55
    Phil,

    That is a very kool utility. Good job!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John J. Couture

    San Diego Miramar College
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2006-03-05 02:12
    Hi Phil,

    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.

    attachment.php?attachmentid=40705

    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
    548 x 99 - 4K
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2006-03-05 02:59
    Hi Tracy,

    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
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2006-03-05 21:03
    Hi Tracy,

    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
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2006-03-06 02:06
    Is there a way to do that directly on the PC, to capture a screen shot of a selection and save it as a web friendly graphic? Maybe a shareware utility? I appreciate the web converter, but I just wonder if there is a way to do it in situ on the PC. The one I uploaded above came from the procedure I described using PrintScn and Paint, but ithe procedure seemed too roundabout. I didn't do anything to change the colors. That is the way they were on the Propeller screen, except that the background color in the GIF came out as rather large dots, instead of solid pale yellow.

    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
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-06 02:23
    Tracy,

    ·· 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
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2006-03-06 02:30
    Hi Tracy,

    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 ClarkeRyan Clarke Posts: 738
    edited 2006-03-06 15:49
    If you want a free Graphics program for Windoze, try GIMP for Windows. A great open source piece of work...


    Ryan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ryan Clarke
    Parallax Tech Support

    RClarke@Parallax.com
Sign In or Register to comment.