[Pharo-users] Can it do this way ?

2020-09-01 Thread Roelof Wobben via Pharo-users
--- Begin Message --- Hello, I have now a challenge where I have to validate a ISBN number. Can I do something like this on the class side : (string isEmpty)    ifTrrue: [ ^ false]   ifFalse:  [ digits:= something.    controlDigit := something.    self validateIS

Re: [Pharo-users] Can it do this way ?

2020-09-01 Thread jtuc...@objektfabrik.de
Roelof, I don't think so. A Class cannot access instance variables. Why? because a Class doesn't know which of its instances to ask for it. Ask yourself: who is "self" in a Class method? Is it the Class or is it an individual instance of the Class? (Hint: in a Class, #self is the Class, whil

Re: [Pharo-users] Can it do this way ?

2020-09-02 Thread Richard O'Keefe
Everything Joachim Tuchel wrote about this is fine EXCEPT that this is an Exercism task, where Roelof has to implement an API that he is given and is not at liberty to do it right. Thanks to the way that IsbnVerifierTest is structured, - the IsbnVerifier class has NO use for ANY variables of ANY

Re: [Pharo-users] Can it do this way ?

2020-09-02 Thread Richard O'Keefe
Briefly, you cannot and (for a different reason) you should not. The IsbnVerifierTest class defines the API; the method must be isValidIsbn: aString and it MUST be on the instance side. The reason why you shouldn't is that an empty string should NOT be a special case. This is a problem where the d

Re: [Pharo-users] Can it do this way ?

2020-09-02 Thread Roelof Wobben via Pharo-users
--- Begin Message --- Yep, I know that isValidIsbn is the method that must output if a isbn is valid or not. What I want to do is take the first 9 characters out so I can convert them to a array of numbers where I can do the calculation on. And take out the last char so I can seperate test if t

Re: [Pharo-users] Can it do this way ?

2020-09-02 Thread Richard O'Keefe
There is simply no point in "taking the first nine numbers out". And there shouldn't BE a test for the string being empty, anywhere. '' '-' '---' and so on should all be handled the same way. Oh well, what stops you doing digits := aString select: [:each | each ~= $-]. digits size = 10 ifFa

Re: [Pharo-users] Can it do this way ?

2020-09-02 Thread Roelof Wobben via Pharo-users
--- Begin Message --- Correct. This is a exercism task. and yes, there are no variables given but that does not in my oponion means that I cannot add a instance or a class variable I myself was thinking about adding two instance variables named digits which hold the first 9 characters and a va

Re: [Pharo-users] Can it do this way ?

2020-09-02 Thread Roelof Wobben via Pharo-users
--- Begin Message --- Op 2-9-2020 om 12:38 schreef Richard O'Keefe: There is simply no point in "taking the first nine numbers out". And there shouldn't BE a test for the string being empty, anywhere.

Re: [Pharo-users] Can it do this way ?

2020-09-03 Thread Roelof Wobben via Pharo-users
Op 2-9-2020 om 12:52 schreef Roelof Wobben via Pharo-users: So no more hints from other people? Roelof

Re: [Pharo-users] Can it do this way ?

2020-09-03 Thread Richard O'Keefe
What part of "return false if there are not exactly 10 characters left after discarding dashes" fails to handle the empty string? A test case for the empty string is is only valuable if the empty string is NOT a special case. On Wed, 2 Sep 2020 at 22:52, Roelof Wobben wrote: > Op 2-9-2020 om 12

Re: [Pharo-users] Can it do this way ?

2020-09-03 Thread Roelof Wobben via Pharo-users
oke, then I could use your idea but then I have to make the code for calculating if its a valid  number. and I wonder if the code will not be too big. I learned that it is good that a method does only 1 thing and this one seems to be doing more then 1 thing.

Re: [Pharo-users] Can it do this way ?

2020-09-03 Thread Roelof Wobben via Pharo-users
Nope, with your idea I cannot make this part work : he ISBN-10 format is 9 digits (0 to 9) plus one check character (either a digit or an X only). In the case the check character is an X, this represents the value '10'. These may be communicated with

Re: [Pharo-users] Can it do this way ?

2020-09-06 Thread Steffen Märcker
Maybe this is a naive question, but can you just split the task into the following two? 1. Check whether whether the string is syntactically an ISBN number. This can be done, e.g., using a regex. 2. Check the the check character. Calculate the check character from the (now to be known) syntactic

Re: [Pharo-users] Can it do this way ?

2020-09-06 Thread Roelof Wobben via Pharo-users
Hello, I solved it but with what I find one big ugly code isValidIsbn: aString     | digits lastDigit acc |     digits := aString select: [ :each | each ~= $- ].     digits size = 10         ifFalse: [ ^ false ].     lastDigit :=

Re: [Pharo-users] Can it do this way ?

2020-09-07 Thread Roelof Wobben via Pharo-users
Op 6-9-2020 om 10:07 schreef Steffen Märcker: Maybe this is a naive question, but can you just split the task into the following two? 1. Check whether whether the string is syntactically an ISBN number. This can be done, e.g., using a regex. 2. Check the the check character. Calculate the check

Re: [Pharo-users] Can it do this way ?

2020-09-07 Thread Steffen Märcker
No problem. I am not knowledgeable about isbn numbers. At which places may a dash occur? Kind regards, Steffen 07.09.2020 16:18:22 Roelof Wobben via Pharo-users : > Op 6-9-2020 om 10:07 schreef Steffen Märcker: >> Maybe this is a naive question, but can you just split the task into the >> follo

Re: [Pharo-users] Can it do this way ?

2020-09-07 Thread Roelof Wobben via Pharo-users
See here for all the tests : https://github.com/exercism/pharo-smalltalk/blob/master/exercises/isbn-verifier/IsbnVerifierTest.class.st#L88 Roelof

Re: [Pharo-users] Can it do this way ?

2020-09-07 Thread Steffen Märcker
Hi, after reading the link and some additional sources, it turns out that a valid ISBN-10 has either no separators or four blocks separated by either dashes or spaces: Group-Publisher-Title-CheckDigit Assuming Regex11 (and that I made no mistake), the following should do the trick: IsbnVarifi

Re: [Pharo-users] Can it do this way ?

2020-09-07 Thread Steffen Märcker
Now having a Workspace at hand, I fixed some minor typos: IsbnVarifier>>isSyntacticIsbn: aString | nonGrouped dashes spaces grouped | nonGrouped := '\d{9}[0-9X]' asRegex. "groups separated by either dashes or spaces" dashes := '\d{1,7}-\d{1,7}-\d{1,7}-[0-9X]'. spaces := '\d{1,7} \d{1,7}

Re: [Pharo-users] Can it do this way ?

2020-09-07 Thread Richard O'Keefe
There are two quite different questions. (1) Where may dashes occur in a real ISBN-10? (2) What does Exercism require in the specification and check in the test cases? For (1) the rules are Each ISBN consists of 5 elements with each section being separated by spaces or hyphens. Three of the five

Re: [Pharo-users] Can it do this way ?

2020-09-07 Thread Roelof Wobben via Pharo-users
Op 8-9-2020 om 04:22 schreef Richard O'Keefe: There are two quite different questions. (1) Where may dashes occur in a real ISBN-10? (2) What does Exercism require in the specification and check in the

Re: [Pharo-users] Can it do this way ?

2020-09-08 Thread Steffen Märcker
Hi Richard and Roelof, thanks for your comprehensive answer. I brought up Regex only to point out alternative solutions. Another one is the following using transducers, where Tee works like the tee command from the command line. IsbnValidator>>isValidIsbn: aString | length countChars sepa

Re: [Pharo-users] Can it do this way ?

2020-09-08 Thread Roelof Wobben via Pharo-users
Op 8-9-2020 om 08:30 schreef Roelof Wobben: Op 8-9-2020 om 04:22 schreef Richard O'Keefe: There are two quite different questions. (1) Where may dashes occur in a real ISBN-10

Re: [Pharo-users] Can it do this way ?

2020-09-08 Thread Richard Sargent
On Tue, Sep 8, 2020, 04:35 Roelof Wobben via Pharo-users < pharo-users@lists.pharo.org> wrote: > Op 8-9-2020 om 08:30 schreef Roelof Wobben: > > Op 8-9-2020 om 04:22 schreef Richard O'Keefe: > > There are two quite different questions. > (1) Where may dashes occur in a real ISBN-10? > (2) What doe