Shop OBEX P1 Docs P2 Docs Learn Events
FORTH - 2swap - Page 2 — Parallax Forums

FORTH - 2swap

2»

Comments

  • prof_brainoprof_braino Posts: 4,313
    edited 2013-06-27 07:31
    Dave Hein wrote: »
    prof_braino, that code is the poster child for programming in something other than Forth. The FHT can be done more compactly and is more readable when programmed in C. Forth is good for some things, but the FHT isn't one of those things.

    There are MANY things that are best done using other tools. If you can do it on C on a workstation, of course do that. This is a very narrow applicability, everybody has a PC just just down load a C library with FFT; but that won't always work on a stock prop board. If you MUST do it on a prop, and GCC isn't finished yet, and you don't have access to workstation resources, and you can choose to use forth, then this is an option. Which is exactly what heater has been trying to do, FFT on a prop using forth.
  • prof_brainoprof_braino Posts: 4,313
    edited 2013-06-27 07:37
    Martin_H wrote: »
    Basically FORTH feels a bit like an assembly language that prevents access to the JMP instruction, so labels can only be used for subroutine names and variable storage. But makes up for it with one heck of a macro facility (its flow of control structures), so you don't mind.

    Exactly. The right tool for the right job. Once we get the feel for how to use it, a given tool can be very handy for that purpose.

    Can I post your CS101 forth examples as downloads and wiki pages on the propforth site? Are any of them in a "finished form" or do some still need work?
  • Martin_HMartin_H Posts: 4,051
    edited 2013-06-27 07:50
    Can I post your CS101 forth examples as downloads and wiki pages on the propforth site? Are any of them in a "finished form" or do some still need work?

    I would be flattered, so feel free to take any FORTH code I post if it will help you. Those samples compile under Gforth, but haven't been ported to PropForth yet. I did PM you my .roman function ported to PropForth. The only breaking changes in PropForth was no case statement or while loop, so I had to tweak the control structures a bit.

    My current CS-101 FORTH project is the sieve of Sieve of Eratosthenes which I can post when it is finished.
  • larsbrinkhofflarsbrinkhoff Posts: 1
    edited 2013-12-11 04:14
    Uses non-standard words ]] [[ and @+.
    ( Output numeral for one decimal digit. )
    
    variable d
    : n[ ( -- u )   :noname  postpone [  depth d ! ;
    : ]n ( u -- )   ]  depth d @ - 0 ?do ]] dup literal + @ emit [[ loop
       postpone drop postpone ; ; immediate
    n[ 0 2 ]n n[ 2 2 2 1 ]n n[ 2 2 1 ]n n[ 2 1 ]n n[ 1 ]n
    n[ 1 2 ]n n[ 2 2 2 ]n n[ 2 2 ]n n[ 2 ]n n[ ]n
    create table , , , , , , , , , ,
    : numeral ( u a -- )   swap cells table + @ execute ;
    
    ( Convert one decimal digit at a time. )
    
    : digit: ( u1 u2 "name" -- )   create , ,
       does> ( u a -- ) @+ swap >r / 10 mod s" ??MDCLXVI" drop r> @ + numeral ;
    0 1000 digit: 1st   2 100 digit: 2nd   4 10 digit: 3rd   6 1 digit: 4th
    : roman ( u -- )   dup 1st dup 2nd dup 3rd 4th ;
    
Sign In or Register to comment.