fig 2.9 compiler / help docs / examples

discuss compiling applications for Puppy
Post Reply
Message
Author
learnhow2code

fig 2.9 compiler / help docs / examples

#1 Post by learnhow2code »

here is fig 2.9, the "easiest" to learn educational language since logo and basic (perhaps.)

http://murga-linux.com/puppy/viewtopic. ... h&id=99110

# fig29 will be in /usr/local/bin
# docs in /root/fig2.9
# examples in /root/fig2.9/examples

package is 2-300k, fig is about 60k, written in python 2.

fig has about 100 commands, is text-based, does some graphics.

.pet file installed okay with tahr, which includes python (so there are no other requirements.)

if you install pygame, you get graphics. if you dont install pygame, you still get graphics :) kind of.

feel free to ask questions here, or in the programming forum.
Last edited by learnhow2code on Sat 02 Jul 2016, 16:14, edited 1 time in total.

learnhow2code

Re: fig 2.9 compiler / help docs / examples

#2 Post by learnhow2code »

learnhow2code wrote:here is fig 2.9, the "easiest" to learn educational language since logo and basic (perhaps.)

https://dox.me/f/eb8SJ if someone could mirror this or help get it posted here, its only 292k.
couldnt find a better hosting option, so i managed to do the pet without the large gif image. you can still get the gif file (recommended for new users) here: http://imgur.com/oZ0zc1M

.pet file now attached to this post.
feel free to ask questions here, or in the programming forum.
Attachments
fig-2.9.pet
(12.82 KiB) Downloaded 1094 times

User avatar
Puppus Dogfellow
Posts: 1667
Joined: Tue 08 Jan 2013, 01:39
Location: nyc

#3 Post by Puppus Dogfellow »

mirror for fig-2.9.pet and related files.

learnhow2code

#4 Post by learnhow2code »

Puppus Dogfellow wrote:mirror for fig-2.9.pet and related files.
thank you very much for that.

im fond of the .pet format, as its relatively simple and easy to make.

for those who are just wild about .deb packages, a guy i know just made this into a .deb file: http://distro.ibiblio.org/refracta/file ... 31_1.0.deb

tahr can load it with:

Code: Select all

cd /root
wget http://distro.ibiblio.org/refracta/files/extra_packages/fig31_1.0.deb
cd /
undeb /root/fig31_1.0.deb
although i recommend commenting out the the "cd /" line, as removing it will let you inspect the contents before moving them to /usr/bin and /usr/share/doc/fig ; i also recommend pasting the code into a text editor before running it, as its generally a good idea.

now, why would you want a .deb over a .pet? you probably wouldnt, unless you wanted to use the same file across your puppy and debian-based distros. most people would prefer the .pet package.
Attachments
logo.16.gz
(8.28 KiB) Downloaded 590 times
Last edited by learnhow2code on Fri 15 Jul 2016, 04:23, edited 1 time in total.

ASD

#5 Post by ASD »

Hi,

Thank you. I am interested, but confused. The deb version seems to be more recent than the pet version, but more importantly it seems to be more than three times the size of the pet version.

Also, I have tahr-6.0.5 and I would normally expect to install any deb package by just left clicking on it (as I would to install any pet).

I have a few prime number (very short) progs which I wrote in GWBasic some 30 years ago. I have no idea about variations in different versions of basic and I may like to seek further advice how to update those progs (in another free version of basic) to handle larger prime numbers (and perhaps be compiled to run faster).
.

learnhow2code

#6 Post by learnhow2code »

ASD wrote:I am interested, but confused. The deb version seems to be more recent than the pet version, but more importantly it seems to be more than three times the size of the pet version.
happy to help. the .pet version was made very recently (a little over a week ago) by me, and the .deb version was made by someone i know, a day or two ago. theyre very close.

the .deb version includes fig29 (2.9) the python 2 version, same as the .pet package. it also includes fig31 (3.1) the python 3 version, which is potentially useful to debian users but i think puppy only has python 2 (fwiw i prefer 2.)

also i removed a large gif file (link here) to make the .pet fit in the 250k limit on this forum.

also there are a few other files (none are required) included in the .deb version.
Also, I have tahr-6.0.5 and I would normally expect to install any deb package by just left clicking on it (as I would to install any pet).
we have the same version of tahr, but i am less familiar with it. i found undeb and i like it, you should be able to install this .deb the way you normally do. (let me know.)
I have a few prime number (very short) progs which I wrote in GWBasic some 30 years ago. I have no idea about variations in different versions of basic and I may like to seek further advice how to update those progs (in another free version of basic) to handle larger prime numbers (and perhaps be compiled to run faster).
.
i would be happy to have a look at small programs and find out whats possible. feel free to paste those here, or in another thread where you think is best.

for a few programs, no change of license is necessary-- will work with you. beyond 3 or 4 programs, id feel more comfortable helping you translate code if its under some gpl-compatible or mit-compatible license. even a simple one. let me know how strict or permissive a license youd like your code to be used/reused under, im pretty flexible.

also if you dont want help translating and just want to know "how do i do [task] in fig?" thats fine too. any code i reply to (specifically) you with will be in the public domain to use however you like.

(none of that is a requirement to use the software here-- fig is very permissively in the public domain so you can use it however you like.)

questions welcome.

ASD

#7 Post by ASD »

Hi again,

Thank you for your helpful response to my post.

As you now stress recommendation of your pet and gif for Pup use (rather than the alternative deb) I will just send you a short PM about my deb test.

I am looking forward to any advice you may have on my GWBasic progs and I will post details later today.

ASD

#8 Post by ASD »

Four GWBasic programs to:

1 Find the actual No of Primes < x (x <= 39602) and, optionally, list them
plus the estimated No and the sum of the natural logs of primes <= x
uses the prime number theorem (the “-1“ adjustment suits small numbers)

2 Find the actual No of Pairs of Twin Primes < x (x <= 39602) and list them
plus the estimated No using the conjecture of Hardy and Littlewood

3 Find the actual No of Primes in intervals of x up to x^2 + 2x (x <= 180)
re the x^2 (prime in every row ) conjecture of Sierpinski with “+ 2x
Attachments
eg.png
(2.99 KiB) Downloaded 973 times

ASD

#9 Post by ASD »

Here are the screen shot listings of the GWBasic programs, numbered as in my post above. The terms "x" (used there) and "n" (used in the listings) are interchangeable.
Attachments
1.png
(19.31 KiB) Downloaded 942 times
2.png
(19.34 KiB) Downloaded 963 times
3.png
(17.89 KiB) Downloaded 968 times
4.png
(19.36 KiB) Downloaded 970 times

ASD

#10 Post by ASD »

Here are the four programs. In each case edit out the last three (dot g z) characters after download.

DOSBox (in tahr-6.0.5 PPM and many Pups) will run GWBasic and GWBasic v 3.23 can be found on the net.

I used v 3.20 to write the programs and if anybody is interested I can post it here with simple instructions for use.
Attachments
1.BAS.gz
(712 Bytes) Downloaded 578 times
2.BAS.gz
(738 Bytes) Downloaded 570 times
3.BAS.gz
(610 Bytes) Downloaded 569 times
4.BAS.gz
(714 Bytes) Downloaded 581 times

learnhow2code

#11 Post by learnhow2code »

ASD wrote:DOSBox (in tahr-6.0.5 PPM and many Pups) will run GWBasic and GWBasic v 3.23 can be found on the net.

I used v 3.20 to write the programs and if anybody is interested I can post it here with simple instructions for use.
hey, would you mind doing those with the save"filename",a option?

i know its possible to find a copy of basic somewhere and run it in dosbox but theres no reason not to upload these in plaintext.

User avatar
Pete
Posts: 660
Joined: Sun 02 Mar 2014, 18:36

#12 Post by Pete »

@ASD

Oh wow, GWBASIC, I had completely forgotten about it, fond memories.
Come to think of it now, also used QB4.5, but that was many, many moons ago. :)

learnhow2code

#13 Post by learnhow2code »

here is 1.BAS

(complete program is slightly further down the thread)

if you want to do a lot of heavy math, i recommend using the inline python feature. it has order of operations, etc.

this will give you an idea of what fig is like, but fig was not designed for people that love math. for them, the inline python feature-- once youre used to it-- is probably the only way to make fig suit your needs. you can do a sieve in pure fig (well, you need log(z) and log(2) for this) and you will get past your 39602 limit, but there you have it.
Last edited by learnhow2code on Sat 02 Jul 2016, 05:51, edited 1 time in total.

ASD

#14 Post by ASD »

Hi,

Thanks for your response. I have been enjoying some Friday night drinks in good company, so I'll respond later tomorrow by editing this post.

Meanwhile, it would be ideal if the last few Lines of "1.BAS" could be completed in "fig" either with or without using the natural logs of the primes together with detailed advice how to run the completed fig version of "1.BAS".

learnhow2code

#15 Post by learnhow2code »

ASD wrote:it would be ideal if the last few Lines of "1.BAS" could be completed in "fig" either with or without using the natural logs of the primes together with detailed advice how to run the completed fig version of "1.BAS".
you compile with fig29 1.fig and then run ./1.fig.py to run the compiled output.

example output with value of 1000000 is included in the code:

Code: Select all

FUNCTION LOG Z
#we dont have a log function in fig, sorry; but we can steal one from python:
LF
PYTHON
    from math import log
    lf = log(z)
    FIG
NOW RETURN LF
FIG

FUNCTION BEEP
    # depends largely on settings 
    X    7    CHR    PRINTS
    FIG

X    CLS    "INPUT 1 to display all primes on screen; to omit them ENTER"    PRINT
F    COLORTEXT 0    HIGHLIGHT 7    LINEINPUT    COLORTEXT 7

TRY
NOW F INT
EXCEPT
NOW 0
RESUME
F NOW

X    "input n for number of primes < n [n MUST BE EVEN]"    PRINT
N    LINEINPUT    INT
X    "WAIT FOR BEEP"                                        PRINT
S    N    TOPWR .5    INT
B    3
DIM  N    DIVBY 2     INT    PLUS 1
A_   ""   ARR    TIMES DIM

WHILE
INDEX    B    PLUS 1    DIVBY 2    INT    PLUS 1    ARRGET A_ INDEX
IFEQUAL INDEX "a"
    PASS
ELSE
    START B   PLUS  1    DIVBY 2    PLUS B
    STOP N    DIVBY 2
    STEP B
    FOR A START STOP STEP
        AINDEX A    PLUS 1
        A_    ARRSET AINDEX "a"    #### A_(A) = "a" 
        NEXT
    IFMORE B S 
        BREAK
        FIG
    FIG

INC B    PLUS 2    SWAP INC B
WEND
C 1    
L 2    LOG    2    CLS
IFEQUAL F 1
    NOW "2\t" PRINTS
    FIG

START 2
STOP N DIVBY 2 
FOR A START STOP 1
    AINDEX A PLUS 1
    CK ARRGET A_ AINDEX
    IFEQUAL CK "a"
        PASS
    ELSE
        NOW C    PLUS 1    SWAP NOW C    #### C=C+1
        Z 2      TIMES A   MINUS 1
        NOW Z    LOG Z     PLUS L    SWAP NOW L    #### L=L+LOG(Z)
        IFEQUAL F 1
            NOW Z PRINTS "\t" PRINTS
            FIG         
        FIG
    NEXT

NOW ""    PRINT    PRINT
LZ Z      LOG Z    MINUS 1
T  Z      DIVBY LZ    INT    PRINT

NOW "" PRINT
NOW "The number of primes not exceeding "          PRINTS    
NOW N    PRINTS    " is "                          PRINTS
NOW C    PRINTS    " v. expected "                 PRINTS
NOW T    PRINTS    " and the largest prime is "    PRINTS
NOW Z    PRINT

NOW "The sum of the natural logs of the primes up to " PRINTS
NOW Z    PRINTS    " is "    PRINTS
NOW L    PRINTS    " and the percentage is "    PRINTS
NOW L    DIVBY Z   TIMES 100    PRINT    BEEP    END


PYTHON
    """
        ==== OUTPUT: ====

$ fig29 1.fig > /dev/null
$ ./1.fig.py 

INPUT 1 to display all primes on screen; to omit them ENTER

input n for number of primes < n [n MUST BE EVEN]
1000000
WAIT FOR BEEP

78029

The number of primes not exceeding 1000000 is 78498 v. expected 78029 and the largest prime is 999983
The sum of the natural logs of the primes up to 999983 is 998484.175026 and the percentage is 99.8501149545
$ 
    """
FIG

ASD

#16 Post by ASD »

Hi learnhow2code,

Thank you very much for your post immediately above. I am impressed by your program code and your example result for n = 1,000,000.
I have not yet understood how to run it myself and will come back again later.

Regarding your questions, GWBasic v 3.20 is below with the usual fake "dot g z" extension needing deletion by renaming.

As to
hey, would you mind doing those with the save"filename",a option?
I'm not very computer language literate so I may not have understood you, but if you wanted to change say, line 30 of "1.BAS" and then save it with a new name you would load 1.BAS by pressing F3 then type 1 and Return
Then instead of using F2 to run 1.BAS you would use F1 to list the program
Then you type edit 30 then make the changes to line 30
Then drop to next line and type save"theNewFileName" (including the inverted commas) or else use F4 to bring up save"

Is there anything more that you would like me to do?

PS My desktop computer is quite fast, but it takes 28 secs to run 1.BAS at its MAX n = 39,602 (35 secs to also show the 4,164 primes).
Attachments
GWBASIC.EXE.gz
(77.02 KiB) Downloaded 544 times

learnhow2code

#17 Post by learnhow2code »

ASD wrote: I have not yet understood how to run it myself and will come back again later.
since you go back to gw-basic (and you run dosbox) i will assume you have dos knowledge i can put to use.

Code: Select all

REM the dos version of it:
c:
cd \
cd gwbasic
cat > HLLOWRLD.BAS
10 COLOR 14
20 PRINT HELLO
[CTRL]-[C] ...on your keyboard

gwbasic HLLOWRLD.BAS
REM or
qbasic /run HLLOWRLD.BAS
REM or
basic HLLOWRLD.BAS
REM or
basica HLLOWRLD.BAS

Code: Select all

# the puppy version of it:
cd /
cd root
cat > helloworld.fig
NOW COLORTEXT 14
NOW "HELLO" PRINT
[CTRL]-[D] ...on your keyboard

fig29 helloworld.fig
./helloworld.fig.py

one of the things fig is used for in an educational setting is introducing people to the term.

however, im sure its possible for someone to make a gui for compiling with fig.

i could make a gui with compiling with fig, and im not against someone doing it (floss, public domain, after all.)

but i wouldnt personally, because the gui will ultimately change and the instructions for it will change. but the command line version i offer works the same (until someone renames the file of course.)

packages are a new thing. normally people can name the program "fig" or whatever they like to name it. in this case its fig29, but you can fig[tab-complete]
PS My desktop computer is quite fast, but it takes 28 secs to run 1.BAS at its MAX n = 39,602 (35 secs to also show the 4,164 primes).
well lets see how long a million takes on an "old, underpowered" 32bit machine without dosbox running:

Code: Select all

$ time ./1.fig.py # this will include the time it takes to paste in 1000000

INPUT 1 to display all primes on screen; to omit them ENTER

input n for number of primes < n [n MUST BE EVEN]
1000000
WAIT FOR BEEP

78029

The number of primes not exceeding 1000000 is 78498 v. expected 78029 and the largest prime is 999983
The sum of the natural logs of the primes up to 999983 is 998484.175026 and the percentage is 99.8501149545

real	0m26.505s
user	0m24.232s
sys	0m0.120s
$ 
now is a good time to find and open the term. in tahr its in the puppy menu under Utilities > URXVT (not the urxvt settings manager-- the one at the bottom of the Utilities menu.)

ASD

#18 Post by ASD »

I am well pleased to report that 1.fig is now working perfectly here, thanks to huge support from learnhow2code [LH2C] in our recent exchanges by PM.

We are both using tahr-6.0.5 which has the needed Python app inbuilt and we are using fig-2.9.pet [written by LH2C and downloadable from above].

It had been working all the time for LH2C, but I encountered two problems; one was unusual and hard for LH2C to solve without access to my m/c.

My tough problem needed me to reset my urxvt colours to white text on a dark background. Alternatively, LH2C recommended I try using rxvt.

The simpler hitch was “permission denied
Attachments
1.fig.gz
(2.05 KiB) Downloaded 561 times
screen_shot.png
(25.63 KiB) Downloaded 417 times

learnhow2code

#19 Post by learnhow2code »

My tough problem needed me to reset my urxvt colours to white text on a dark background. Alternatively, LH2C recommended I try using rxvt.
yes, the main problem (from what i can tell) is that the term in tahr is light-colored, and 1.fig was written for a darker term.

avoiding the color commands in fig (or trying it in a lighter colored rxvt) would have saved us a lot of trouble for this demo.

The simpler hitch was “permission denied

Post Reply