Re: [Ql-Users] Quanta Library Guide

2012-04-22 Thread Ralf Reköndt
Ah, seems I am wrong. If e.g. win1_mach_ ist not found, I think, TK2 
searches for win1_win1_mach_.


I use the following (extract from S_Edit ;-)):

SV_BASE is my keyword to return the base of the system variables:

12480 DEFine FuNction file_test(name$)
12490 LOCal default
12495 REMark Read the length of DATAD$
12500 default=PEEK_W(PEEK_L(SV_BASE+176))
12506 REMark set the length of DATAD$ to zero, the string itself remains
12510 POKE_W PEEK_L(SV_BASE+176),0
12520 ferr=FOP_IN(#5,name$)
12530 CLOSE#5
12535 REMark restore the length of DATAD$
12540 POKE_W PEEK_L(SV_BASE+176),default
12550 RETurn ferr
12560 END DEFine file_test

I set the data_default to , so I really know, if the file exists or not.

Cheers...Ralf


- Original Message - 
From: Ralf Reköndt ralf.rekoe...@t-online.de

To: ql-us...@q-v-d.com
Sent: Saturday, April 21, 2012 6:50 PM
Subject: Re: [Ql-Users] Quanta Library Guide


The FOP_xxx functions (and all similar TK2 things) always tried to use the
Data default next, if a direct call was unsuccessful.

So, if I try to check Win1_test_, and it does not exist, Win1_ is checked
next (if Data default), which is very likely to be successful.

So you can't be sure, that the correct device was opened. That's why it is
better, to set the Data default to , then try, then set it back to where
it was before.

- Original Message - 
From: Bob Spelten b...@upcmail.nl

To: ql-us...@q-v-d.com
Sent: Saturday, April 21, 2012 5:43 PM
Subject: Re: [Ql-Users] Quanta Library Guide


Op Sat, 21 Apr 2012 16:10:15 +0200 schreef Ralf Reköndt
ralf.rekoe...@t-online.de:

Hmm, but the TK2 Manual states about OPEN_DIR, so, apart from Level 2,  it 
should be possible. But what kind of directory, if not Level 2?  Perhaps 
just the root one.


Section 10  Open and Close

   The standard QL channel OPEN commands are redefined by Toolkit II
   to use the data directory. In addition, Toolkit II provides a set
   of functions for opening files either using a specified channel
   number (as in the standard QL commands), or they will find and
   return a vacant channel number. The functions also allow filing
   system errors to be intercepted and processed by SuperBASIC
   programs.

   Commands

 OPEN #channel, nameopen a file for read/write
 OPEN_IN #channel, name open a file for input only
 OPEN_NEW #channel, nameopen a new file
 OPEN_OVER #channel, name   open a new file, if it
  exists it is overwritten
 OPEN_DIR #channel, nameopen a directory

 CLOSE #channelsclose channels


The problem is related to the FTEST command trying to open a file rather 
than a directory to verify its existance. In SMSQ/E a directory can be 
opened as a file, but in QDOS I don't think it can. The correct way to 
check for the validity of devices and directories would be to attempt to 
open a directory, not a file (TRAP#2 with D0=1 and D3=4 rather than 
D3=1).



The Function FOP_DIR can be used but is not very reliable.
I did a quick QDOS test on my demo Q-emuLator where win1_ is a W$ folder,
win2_ is a QL floppy.

chn= FOP_DIR (win1_): PRINT FTYP(#chn): produced 255.
chn= FOP_DIR (win1_mach_): PRINT FTYP (#chn): also produced 255 while
mach_ is part of a filename and not a directory!
Even chn FOP_DIR (win1_ma): PRINT FTYP (#chn): returned as valid
directory.

This was not the case with win2_, there a FTYP returned zero for
everything.

But chn= FOP_DIR (usb1): opened a channel to win2_, PRINT FTYP(#chn):
returned zero and DIR usb1_ gave the name of the floppy and the sector
count.

So this is here not a good level 1 test to see if a device or directory
actually exists.
Minerva gave the same results.
Mind you, even under QPC2 I can happily FOP_OVER (a_file) to my win8_,
which is a QXL.WIN on the cdrom!

Bob

--
The BSJR QL software site at: http://members.upc.nl/b.spelten/ql/
___
QL-Users Mailing List
http://www.q-v-d.demon.co.uk/smsqe.htm

___
QL-Users Mailing List
http://www.q-v-d.demon.co.uk/smsqe.htm 


___
QL-Users Mailing List
http://www.q-v-d.demon.co.uk/smsqe.htm


Re: [Ql-Users] Raspberry Pi - starts

2012-04-22 Thread Malcolm Cadman
In message 4f92c11b.8080...@dunbar-it.co.uk, Norman Dunbar 
nor...@dunbar-it.co.uk writes



Hi Bryan,

On 21/04/12 10:21, Bryan Horstmann wrote:

The only things I know about Python are from the Cheat Sheet I mentioned
earlier. But where are the equivalent of all the many other S*BASIC
Keywords?


Python isn't S*Basic, so most of the well known and loved S*Basic 
commands and keywords etc will not be there.


Norm.


As Norman says ... it is not a BASIC, so not all the 'helpers' as 
'keywords', like in S*BASIC


Its antecedents are in C/C++, so it more open ended than a BASIC 
programming language.


--
Malcolm Cadman
___
QL-Users Mailing List
http://www.q-v-d.demon.co.uk/smsqe.htm


Re: [Ql-Users] Raspberry Pi - starts

2012-04-22 Thread Malcolm Cadman
In message 77845c9e-9410-4678-a5d7-ac1476607...@firshman.co.uk, Tony 
firshman t...@firshman.co.uk writes



On 18 Apr 2012, at 17:31, Malcolm Cadman q...@mcad.demon.co.uk wrote:

In message 4f8e8d97.7070...@newlan.org, Bryan Horstmann 
b...@newlan.org writes


Hi Bryan,

Thanks for the link.

I believe that everything is covered within functions, yet I haven't 
programmed enough with Python to see if that is an advantage or a 
limitation.


PS - You are not the Bryan, named in a Python film, are you? ... :-)

Silly - that was 'Brian' (8-)#

Tony
(Looking on the bright side of life)


Yes, yet he may have cunningly disguised himself, as Bryan, to fool his 
followers ... :-)


--
Malcolm Cadman
___
QL-Users Mailing List
http://www.q-v-d.demon.co.uk/smsqe.htm


Re: [Ql-Users] Raspberry Pi - starts

2012-04-22 Thread Malcolm Cadman
In message 4f927160.2090...@dunbar-it.co.uk, Norman Dunbar 
nor...@dunbar-it.co.uk writes


Hi Norman,

Great ... :-) ... we need you to write an easy-peasy Guide to Python!

I have been experimenting with a rather 'old version' - 2.5.2 - dated at 
2008, that I never quite got around to using before the Raspberry Pi 
revival came along.


With the PC Windows version, there is a separate 'interpreter' window 
that runs and compiles, as you say, much like a BASIC. Easy ... :-)


I have just updated to 3.7, on Windows, 32 bit version for my machines.



Morning all,

On 20/04/12 21:40, Dilwyn Jones wrote:

This all sounds very interesting and possibly a fairly straightforward
language for S*BASIC users to learn. I notice there's versions of Python
for Windows as well as Linux etc. Anyone know if a Python program
written on one platform such as Windows, be run on another such as
Linux?
Yes. There's a few ways to run a python program on Linux/Unix either by 
telling the python interpreter the name of the file:


  python filename.py

or by putting this as the first line in the program:

  #!/usr/bin/env python

then making it executable:

  chmod u+x filename.py

then simply calling it:

  ./filename.py

Under windows, only the first option is available and if the program 
contains the #!/usr/bin/env python line, it gets treated as a comment 
and completely ignored.


There's also a python interpreter which sits there and waits for you to 
type something  in, then compiles and executes it.




Guess if the programs are written and saved using a text editor
there's a chance this might be possible, although probably endian issues
might arise with numbers, for example?
There's no problem with endians or numbers etc, well, not those 
problems anyway! There are gotchas to watch out for with numbers:


  print 3 / 4
  0

The '/' operator is equivalent to integer DIV. If you want to get a 
floating point answer, you need to float one or both operands:


  print float(3) / float(4)
  0.75

or

  print float(3) / 4
  0.75

or, simply:

  print 3 / 4.0
  0.75

Python is pretty nifty in it's ability to coerce variables from one 
type to another, so in the above, it sees one float argument and 
coerces the int argument into float and gives back a float answer.


It doesn't coerce strings to floats, or ints:

  print '313' + 300 + '13'

  Traceback (most recent call last):
File pyshell#14, line 1, in module
  print '313' + 300 + '13'
  TypeError: cannot concatenate 'str' and 'int' objects

But you can do it implicitly:

  print int('313') + 300 + int('13')
  626

And not necesarily in base 10 either:

  print int('313', 16) + 300 + int('13', 8)
  1098

Which is obviously 787 + 300 + 11.



Admittedly I know nothing about Python (yet... - it looks interesting)
You may not know Python yet, but you are using it frequently! Calibre, 
your most favourite program of recent times, is written in Python. So 
you can see it's a capable programming language.


The use of indents in interesting. You do do this in Python:

  #!/usr/bin/env python

  Dilwyn = 'Jones'
  Tony = 'Firshman'
  Malcolm = 'Cadman'

  if (Dilwyn == Tony):
  print Tony and Dilwyn and the same person!
  elif (Tony == Malcolm):
  print Clones are people two!
  else:
  print Everyone is an individual.

The colons mark the start of a block, which must be indented (4 spaces 
is the Python standard). The block ends when the indent comes back out.


Typing the file above using into vi was interesting as it understands 
the indentation and did it for me automagically, probably based on the 
file name (ql.py).


In case anyone is wondering, the else clause is executed.

Arrays are the usual stuff but are called lists:

  ql_people = [Dilwyn, Tony, Marcel, Jochen, ]

To print them out, for example:

  for person in ql_people:
  print This person is: $s % person

They can also be dictionaries. These are like lists, but hava an access 
key, and use different open/close brackets:


  ql_people = {'Jones': 'Dilwyn', Firshman: Tony}
  print ql_people['Jones']
  Dilwyn

So, you could use a dictionary to define a record of some sort:

  dj = {'name': 'Dilwyn Jones',
'age': 32,
'nationality': 'Welsh',
'lives in': 'Tal-y-Bont'}

  print dj
  {'nationality': 'Welsh', 'age': 32, 'name': 'Dilwyn Jones',
  'lives in': 'Tal-y-Bont'}

  print dj['lives in']
  Tal-y-Bont

  print dj['name'], dj['age']
  Dilwyn Jones 32

You can even add functions to dictionaries. Then, a step up from 
dictionaries is a class. But I'll not bother with that, I think I've 
warbled on long enough!



For Python beginners there are a couple of decent books, one of which I 
got free from Amazon for my Kindle:


Hello Python: