Help: VW Smalltalk 2.5 
Author Message
 Help: VW Smalltalk 2.5

My apologies for what might seem to be a trivial question, but I'm quite
new to it all.  It involves getting a character from one string and
placing it on the end of another.

We're trying to fork off a process in UNIX, and we need to provide the
commandline arguments as an array of strings

eg #('-display' 'myDisplay:0.0' '-bg' 'black')

We've tried just doing: #('-display myDisplay:0.0 -bg black'), but the
fork doesn't do anything if there are spaces in the arguments string.

This brings me to our problem, at the moment are arguments are arriving
as one long string, and we want to break it into an array of substrings.  
Unfortunately, when we try and access individual characters within a
string we get back something completed unexpected, which can be simulated
by doing a 'print it' on:

$a printString

This returns:  '$a "16r0061"'

It appears to be a two byte character, and if it is concatenated onto the
end of another string, all of it including the quoted section is
appended.  Is there anyway to append a character to a string?

eg.  'Tes', ($t printString) (currently returns: 'Tes$t "16r0074"')

Any help in the matter would be greatly appreciated.

--
+----------------------------------------------------------------------+
|  Malcolm Ferguson, BSc. (Hons) Computer Science                      |
|  University of East Anglia, Norwich, England                         |
|                                                                      |

+----------------------------------------------------------------------+
Read about the boys: http://www.*-*-*.com/
                      http://www.*-*-*.com/



Mon, 25 Jan 1999 03:00:00 GMT  
 Help: VW Smalltalk 2.5

Thanks to the people who've answered my query... we've solved it.

It would appear that (our version) of VisualWorks 2.5 doesn't quite do
what you would expect with turning characters into strings.  The solution
involves creating another string as follows: 'Tes', (String with: $t)

Malcolm

--
+----------------------------------------------------------------------+
|  Malcolm Ferguson, BSc. (Hons) Computer Science                      |
|  University of East Anglia, Norwich, England                         |
|                                                                      |

+----------------------------------------------------------------------+
Read about the boys: http://www.mbcis.co.uk/mbb
                     http://www.bbcnc.org.uk/tv/entertainment/menbbadly/



Tue, 26 Jan 1999 03:00:00 GMT  
 Help: VW Smalltalk 2.5


Quote:

> [snipped]

> $a printString

> This returns:  '$a "16r0061"'

This is correct.  This is just a printing convention to support Unicode.
Note the hex value is in double-quotes, a lexical comment.  Whether it is
a one or two byte character depends on the concrete string class.  More
than likely, its one byte from a ByteString.

Quote:
> It appears to be a two byte character, and if it is concatenated onto the
> end of another string, all of it including the quoted section is
> appended.  Is there anyway to append a character to a string?

> eg.  'Tes', ($t printString) (currently returns: 'Tes$t "16r0074"')

You should use:

        'Tes' copyWith: $t
    or
        'Tes' , (String with: $t)

... similar to other arrayed collection behavior.

Tom Hawker



Tue, 26 Jan 1999 03:00:00 GMT  
 Help: VW Smalltalk 2.5


zum Thema "Help: VW Smalltalk 2.5":

Quote:
>  Is there anyway to
> append a character to a string?

> eg.  'Tes', ($t printString) (currently returns: 'Tes$t
> "16r0074"')

> Any help in the matter would be greatly appreciated.

Try this:
         ('Tes',($t asString)) asString.
Quote:
> --
> +-------------------------------------------------------------
> ---------+ |  Malcolm Ferguson, BSc. (Hons) Computer Science
>                    | |  University of East Anglia, Norwich,
> England                         | |
>                                           | |  email:

> +-------------------------------------------------------------
> ---------+ Read about the boys: http://www.mbcis.co.uk/mbb
>                      http://www.bbcnc.org.uk/tv/entertainment/
> menbbadly/



Tue, 26 Jan 1999 03:00:00 GMT  
 Help: VW Smalltalk 2.5

I don't know if this is available in VisualWorks but in
Visual Smalltalk 3.1 the String class has a method called

   asArrayOfSubstrings

which answers a collection of substrings of the receiving string where
the substrings are delimited by one or more whitespace characters.
Sounds like it'd do what you want if it's available in VW.  Hope
this helps.

Bob Jarvis

*************************** Attachment ***********************************
Date: 09 August 1996, 11:07:13 EDT
From: M. Ferguson CMP UG                             u9324364 at INTERNET

To: Multiple recipients of list                    smalltal at INTERNET

Reply-To:                                                u9324364 at INTERNET

Subject: Help: VW Smalltalk 2.5


Precedence: bulk
X-Comment: Usenet News "comp.lang.smalltalk"
My apologies for what might seem to be a trivial question, but I'm quite
new to it all.  It involves getting a character from one string and
placing it on the end of another.

We're trying to fork off a process in UNIX, and we need to provide the
commandline arguments as an array of strings

eg #('-display' 'myDisplay:0.0' '-bg' 'black')

We've tried just doing: #('-display myDisplay:0.0 -bg black'), but the
fork doesn't do anything if there are spaces in the arguments string.

This brings me to our problem, at the moment are arguments are arriving
as one long string, and we want to break it into an array of substrings.
Unfortunately, when we try and access individual characters within a
string we get back something completed unexpected, which can be simulated
by doing a 'print it' on:

$a printString

This returns:  '$a "16r0061"'

It appears to be a two byte character, and if it is concatenated onto the
end of another string, all of it including the quoted section is
appended.  Is there anyway to append a character to a string?

eg.  'Tes', ($t printString) (currently returns: 'Tes$t "16r0074"')

Any help in the matter would be greatly appreciated.

--
+----------------------------------------------------------------------+
|  Malcolm Ferguson, BSc. (Hons) Computer Science                      |
|  University of East Anglia, Norwich, England                         |
|                                                                      |

+----------------------------------------------------------------------+
Read about the boys: http://www.mbcis.co.uk/mbb
                     http://www.bbcnc.org.uk/tv/entertainment/menbbadly/



Tue, 26 Jan 1999 03:00:00 GMT  
 Help: VW Smalltalk 2.5

Quote:

> I don't know if this is available in VisualWorks but in
> Visual Smalltalk 3.1 the String class has a method called

>    asArrayOfSubstrings

> which answers a collection of substrings of the receiving string where
> the substrings are delimited by one or more whitespace characters.
> Sounds like it'd do what you want if it's available in VW.  Hope
> this helps.

In VisualWorks, try the following:

        '123 456 789' tokensBasedOn: Character space

--
Alan L. Lovejoy         | Separate interface from implementation, policy from


Smalltalk Consultant    | basis for assigning responsibility. Find invariants.



Tue, 26 Jan 1999 03:00:00 GMT  
 Help: VW Smalltalk 2.5

On 9 Aug 1996 14:51:11 GMT,


Quote:
>Thanks to the people who've answered my query... we've solved it.

>It would appear that (our version) of VisualWorks 2.5 doesn't quite do
>what you would expect with turning characters into strings.  The solution
>involves creating another string as follows: 'Tes', (String with: $t)

Yes ... Smalltalk rarely (the exception is subclasses of Number)
converts operands in the course of operations.  The #, selector is
used to concatenate two COLLECTIONS, so it concatenated what you had
with the little UNICODE character collection.  This is not, as you
noticed, what you'd expect coming from "conventional" languages.
Overall, when you get experience with Smalltalk, you'll probably agree
that it's the best thing.

Word of warning: it is tempting to "fix" things like this.  My advice
is not to do so, even though it'd be easy.  When your methods get TOO
flexible in accepting whatever might come along, code reliability goes
down, due to missing the error messages that would have come out.

So ... good luck getting used to a new world ... and proceed
cautiously.  It's worth it!

Ron



Thu, 28 Jan 1999 03:00:00 GMT  
 Help: VW Smalltalk 2.5


Quote:
> We're trying to fork off a process in UNIX, and we need to provide the
> commandline arguments as an array of strings

> eg #('-display' 'myDisplay:0.0' '-bg' 'black')

> We've tried just doing: #('-display myDisplay:0.0 -bg black'), but the
> fork doesn't do anything if there are spaces in the arguments string.

> This brings me to our problem, at the moment are arguments are arriving
> as one long string, and we want to break it into an array of substrings.
> Unfortunately, when we try and access individual characters within a
> string we get back something completed unexpected, which can be simulated
> by doing a 'print it' on:

> $a printString

> This returns:  '$a "16r0061"'

> It appears to be a two byte character, and if it is concatenated onto the
> end of another string, all of it including the quoted section is
> appended.  Is there anyway to append a character to a string?

> eg.  'Tes', ($t printString) (currently returns: 'Tes$t "16r0074"')

> Any help in the matter would be greatly appreciated.

Here are two methods you can add to the String class to solve the two problems.

Problem #1: breaking a string into a collection of substrings:

asOrderedCollectionOfSubstrings
        "return an array of the substrings of the receiver, delimited by spaces"

        | reader result |
        reader := ReadStream on: self.
        result := OrderedCollection new.
        [reader atEnd]
                whileFalse: [result add: (reader upTo: $ )].
        ^result

Problem #2: Appending a single character to a string:

appendChar: aChar
        "Add aChar to the end of the receiver."

        | str |
        str := String new: self size + 1.
        (1 to: self size + 1)
                do: [:i | i <= self size
                                ifTrue: [str at: i put: (self at: i)]
                                ifFalse: [str at: i put: aChar]].
        ^str



Sat, 30 Jan 1999 03:00:00 GMT  
 Help: VW Smalltalk 2.5


Quote:

> My apologies for what might seem to be a trivial question, but I'm quite
> new to it all.  It involves getting a character from one string and
> placing it on the end of another.

> We're trying to fork off a process in UNIX, and we need to provide the
> commandline arguments as an array of strings

> eg #('-display' 'myDisplay:0.0' '-bg' 'black')

> We've tried just doing: #('-display myDisplay:0.0 -bg black'), but the
> fork doesn't do anything if there are spaces in the arguments string.

> This brings me to our problem, at the moment are arguments are arriving
> as one long string, and we want to break it into an array of substrings.
> Unfortunately, when we try and access individual characters within a
> string we get back something completed unexpected, which can be simulated
> by doing a 'print it' on:

> $a printString

> This returns:  '$a "16r0061"'

> It appears to be a two byte character, and if it is concatenated onto the
> end of another string, all of it including the quoted section is
> appended.  Is there anyway to append a character to a string?

> eg.  'Tes', ($t printString) (currently returns: 'Tes$t "16r0074"')

> Any help in the matter would be greatly appreciated.

> --
> +----------------------------------------------------------------------+
> |  Malcolm Ferguson, BSc. (Hons) Computer Science                      |
> |  University of East Anglia, Norwich, England                         |
> |                                                                      |

> +----------------------------------------------------------------------+
> Read about the boys: http://www.mbcis.co.uk/mbb
>                      http://www.bbcnc.org.uk/tv/entertainment/menbbadly/

        Try

'Tes' , (String with: $t)

John



Sun, 31 Jan 1999 03:00:00 GMT  
 Help: VW Smalltalk 2.5

Quote:

> Try this:
>          ('Tes',($t asString)) asString.

I get: 'Tes$t'  
close.


Fri, 05 Feb 1999 03:00:00 GMT  
 Help: VW Smalltalk 2.5

Dolphin Smalltalk evaluates

   'Tes', $t asString

as

   'Tes$t'

VS 3.1 evaluates it as

   'Test'

Personally, I expect that it *should* be evaluated as 'Test' (my
reasoning is: $t asString should be evaluated first, followed by
'Tes', 't'.  This assumes that $t asString evaluates to 't', which
Dolphin obviously doesn't.  (Dolphin doesn't implement a separate
Character>>asString, so Object>>asString gets invoked, and
Object>>asString just answers the results of #printString).  I'd guess
that an answer of 'Tes$t' could potentially break a lot of code).

Bob Jarvis

*************************** Attachment ***********************************
Date: 19 August 1996, 13:37:44 EDT
From: Robert J. Sullivan                             rjs      at INTERNET

To: Multiple recipients of list                    smalltal at INTERNET

Reply-To:                                                rjs      at INTERNET

Subject: Re: Help: VW Smalltalk 2.5


Precedence: bulk
X-Comment: Usenet News "comp.lang.smalltalk"

Quote:

> Try this:
>          ('Tes',($t asString)) asString.

I get: 'Tes$t'
close.


Sat, 06 Feb 1999 03:00:00 GMT  
 Help: VW Smalltalk 2.5

Quote:

>Dolphin Smalltalk evaluates
>   'Tes', $t asString
>as
>   'Tes$t'
>VS 3.1 evaluates it as
>   'Test'
>Personally, I expect that it *should* be evaluated as 'Test' (my
>reasoning is: $t asString should be evaluated first, followed by
>'Tes', 't'.  This assumes that $t asString evaluates to 't', which
>Dolphin obviously doesn't.  (Dolphin doesn't implement a separate
>Character>>asString, so Object>>asString gets invoked, and
>Object>>asString just answers the results of #printString).  I'd guess
>that an answer of 'Tes$t' could potentially break a lot of code).

Bob,

You're absolutely right; this is a bug in the Dolphin Character class.

#asString should be defined in Character (it is part of the Character
protocol in the draft ANSI standard). You can fix the problem by
defining:

Character>>asString
        ^String with self

This will be fixed in the next beta.

Andy Bower



Mon, 08 Feb 1999 03:00:00 GMT  
 Help: VW Smalltalk 2.5

: Dolphin Smalltalk evaluates

:    'Tes', $t asString

: as

:    'Tes$t'

: VS 3.1 evaluates it as

:    'Test'

: I'd guess
: that an answer of 'Tes$t' could potentially break a lot of code).

What breaks the code is the message #asString, because it is ill-defined.
If you need to append a Character to a String, consider these alternatives,
which should work for (almost) all known Smalltalks in the universe:

'Tes' copyWith: $t

'Tes', (String with: $t) "This one does not work for GemStone < 5.0"

Hans-Martin



Mon, 08 Feb 1999 03:00:00 GMT  
 Help: VW Smalltalk 2.5


Quote:

> > Try this:
> >          ('Tes',($t asString)) asString.

> I get: 'Tes$t'  
> close.

Perhaps this would be better:
'Tes', (String with: $t)

]{evin

--
Kevin Driedger                  |CrossKeys Systems Corporation

http://www.synapse.net/~driedge |Service Level Management Solutions



Sun, 14 Feb 1999 03:00:00 GMT  
 
 [ 14 post ] 

 Relevant Pages 

1. VW 2.5 startup screen HELP

2. HELP: VW 2.5 Mac -> WinNT Port

3. HELP (VW 2.5): Windows version

4. Need VW 2.5 Help

5. Stone Age text editing in VW 2.5

6. Sound in VW 2.5

7. VW 2.5 Rubberbanding, howto?

8. VWave 1.0 (VW 2.5 may apply)

9. VW 2.5 MultiRow Select Table Widget Needed

10. VW 2.5 menuBar hide, show

11. VW 2.5 automated testing tools

12. Sound in VW 2.5

 

 
Powered by phpBB® Forum Software