Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.sys.acorn.programmer > #954
| Date | 2011-10-30 16:50 +0000 |
|---|---|
| From | Matthew Phillips <spam2011m@yahoo.co.uk> |
| Newsgroups | comp.sys.acorn.programmer |
| Subject | Re: BASIC and uppercase |
| Message-ID | <96805f2a52.Matthew@sinenomine.freeserve.co.uk> (permalink) |
| References | <cfae0b2a52.beeb@ron1954.woosh.co.nz> <63bc2e2a52.Matthew@sinenomine.freeserve.co.uk> <4539322a52.beeb@ron1954.woosh.co.nz> <c1b3392a52.beeb@ron1954.woosh.co.nz> |
In message <c1b3392a52.beeb@ron1954.woosh.co.nz>
on 30 Oct 2011 Ron wrote:
> In message <4539322a52.beeb@ron1954.woosh.co.nz>
> Ron <beeb@woosh.co.nz> wrote:
> > >
> > > You could try:
> > >
> > > DEFFNupcase(input$)
> > > LOCAL pos%
> > > LOCAL table%
> > > IF input$="" THEN =""
> > > SYS"Territory_UpperCaseTable",-1 TO table%
> > > FOR pos%=1 TO LEN(input$)
> > > MID$(input$,pos%,1) = CHR$( table% ? ASC(MID$(input$,pos%,1)) )
> > > NEXT
> > > = input$
> > >
> > > This uses the Territory module to find the upper case conversion table, so
> > > should work whatever alphabet the machine is using (apart from UTF-8 and
> > > things like that).
> > >
> > > Note the use of assigning to MID$ which avoids having to have a separate
> > > buffer to build the string in.
> > >
> > Thanks, the THEN ="" is new to me.
IF <condition> THEN <commands>
is the way some flavours of BASIC require it to be written. BBC BASIC can
possibly cope with
IF input$="" =""
(I've not tested) but it looks so horrible it's clearer with THEN even if
it's not syntactically necessary.
The ="" is simply returning a blank string from the function: ENDPROC or =
can return from anywhere within a PROC or FN repectively, not just from the
last line of it. It's sometimes considered bad form to do this as some
people expect functions and procedures only to have one point of exit, but
personally I think it's simpler than vast long nested conditional clauses.
> > As is the CHR$( table% ? but I'll try this out and observe.
> >
> Checked it out, and there seems to be no difference if I REM
> IF input$="" THEN =""
> and have a input$ of ""
BBC BASIC (unlike Locomotive BASIC which I cut my teeth on) always executes a
FOR NEXT loop a minimum of one time, even if the end value of the loop range
is less than the beginning value. So "FOR pos%=1 TO 0" executes once, and so
does "FOR pos%=1 TO 1". You might expect the former to execute one fewer
time (i.e. not at all). This feature seems to me very odd, and it can cause
difficulties if you're not aware of it.
My inclusion of the line saying
IF input$="" THEN =""
is an example of defensive programming. I wouldn't like to say that
assigning to
MID$(a$,1,1)
where a$ is an empty string would be OK in all flavours of BASIC, and if you
try
PRINT ASC(MID$("",1,1))
you will get -1 and you certainly have no guarantee that the memory at
table%-1 is available for reading a byte from: it's conceivable (without
knowing more information about the inner workings of the operating system)
that that logical address is unmapped and reading from it could result in an
address exception.
(As it happens, it works fine on my machine this afternoon, but I don't like
relying on it.)
> I got the above function working with
> MID$(input$,pos%,1) = CHR$(?(table%+ASC(MID$(input$,pos%,1))))
Yes,
?(a%+b%)
is equivalent to
a%?b%
The latter is just another way of writing it. It's available with the !
operator as well, but not with $ as far as I remember.
--
Matthew Phillips
Durham
Back to comp.sys.acorn.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
BASIC and uppercase Ron <beeb@woosh.co.nz> - 2011-10-30 14:34 +1300
Re: BASIC and uppercase Matthew Phillips <spam2011m@yahoo.co.uk> - 2011-10-30 07:57 +0000
Re: BASIC and uppercase Ron <beeb@woosh.co.nz> - 2011-10-30 21:35 +1300
Re: BASIC and uppercase Ron <beeb@woosh.co.nz> - 2011-10-30 22:57 +1300
Re: BASIC and uppercase "John Williams (News)" <UCEbin@tiscali.co.uk> - 2011-10-30 11:38 +0100
Re: BASIC and uppercase Matthew Phillips <spam2011m@yahoo.co.uk> - 2011-10-30 16:50 +0000
Re: BASIC and uppercase Rick Murray <heyrickmail-usenet@yahoo.co.uk> - 2011-10-31 01:02 +0100
Re: BASIC and uppercase Steve Drain <steve@kappa.me.uk> - 2011-10-31 15:47 +0000
Re: BASIC and uppercase Rick Murray <heyrickmail-usenet@yahoo.co.uk> - 2011-10-31 20:06 +0100
Re: BASIC and uppercase Rick Murray <heyrickmail-usenet@yahoo.co.uk> - 2011-10-31 00:28 +0100
Re: BASIC and uppercase Ron <beeb@woosh.co.nz> - 2011-10-31 17:04 +1300
Re: BASIC and uppercase Rick Murray <heyrickmail-usenet@yahoo.co.uk> - 2011-10-31 16:12 +0100
Re: BASIC and uppercase jgharston <jgh@arcade.demon.co.uk> - 2011-11-01 04:51 -0700
Re: BASIC and uppercase "Ste (news)" <steve@revi11.plus.com> - 2011-10-31 01:03 +0000
Re: BASIC and uppercase Steve Drain <steve@kappa.me.uk> - 2011-10-31 19:48 +0000
Re: BASIC and uppercase Rick Murray <heyrickmail-usenet@yahoo.co.uk> - 2011-11-01 21:11 +0100
Re: BASIC and uppercase Steve Drain <steve@kappa.me.uk> - 2011-11-02 14:26 +0000
Re: BASIC and uppercase Steve Drain <steve@kappa.me.uk> - 2011-10-31 11:10 +0000
Re: BASIC and uppercase Chris Johnson <chrisjohnson+news@spamcop.net> - 2011-10-30 08:44 +0000
Re: BASIC and uppercase Ron <beeb@woosh.co.nz> - 2011-10-30 22:52 +1300
Re: BASIC and uppercase Alan Adams <alan@adamshome.org.uk> - 2011-10-30 15:16 +0000
Re: BASIC and uppercase Ron <beeb@woosh.co.nz> - 2011-10-31 14:37 +1300
Re: BASIC and uppercase Rick Murray <heyrickmail-usenet@yahoo.co.uk> - 2011-10-31 16:15 +0100
Re: BASIC and uppercase Ron <beeb@woosh.co.nz> - 2011-11-01 11:39 +1300
Re: BASIC and uppercase Rick Murray <heyrickmail-usenet@yahoo.co.uk> - 2011-11-01 21:21 +0100
csiph-web