Re: [Pharo-users] can I somehow test the contents of a package

2020-02-14 Thread phil
I have made some edits. Please check.
https://drive.google.com/uc?id=1yjAdoDnfoMvxGf9KG2RGedjXvNQdwOee=download
Archive password: 





Re: [Pharo-users] can I improve this

2018-12-03 Thread phil--- via Pharo-users
--- Begin Message ---
 CyclicReadStream. Not in base Pharo.

I wish.

We have atWrap: but not the best.

Phil

On Mon, Dec 3, 2018 at 1:17 PM Richard O'Keefe  wrote:

> "if I use do:   this ends at the end of the array."
> True.  But all that means is that you have to keen on using #do:.
>
> Processing an array repeatedly is as simple as
>   [true] whileTrue: [
> anArray do: [:each |
>   ...]]
>
> I had intended to twist this into
>
>   [changes anySatisfy: [:change | ...]] whileFalse.
>
> However, in this case your second alternative has much to recommend it.
> The control flow is simple.  There's no magic about it.  It's an
> unusual setup, so no need to get fancy.
>
>   seen := Set new.
>   frequency := 0.
>   found := false.
>   i := changes size.
>   [found] whileFalse: [
> i := i = changes size ifTrue: [1] ifFalse: [i+1].
> frequency := frequency + (changes at: i).
> found := seen includes: frequency.
> seen add: frequency].
>
> I like this better than what I had.
>
> If we _were_ to get fancy, then introducing a CyclicReadStream
> class and doing
> seen := Set new.
> frequency := 0.
> found := false.
> stream := CyclicReadStream on: self changes.
> [found] whileFalse: [
>   frequency := frequency + stream next.
>   found := seen includes: frequency.
>   seen add: frequency].
> wouldn't shrink the code much.  Oddly enough, I've encountered
> problems in previous Advent of Code exercises where CyclicReadStream
> would have been handy.  But just for this case?  No.
>
>
> On Tue, 4 Dec 2018 at 00:25, Roelof Wobben  wrote:
>
>> hello Richard,
>>
>> Thanks, I figured that out already.
>> What I do not get is how to read the array multiple times.
>>
>> if I use do:   this ends at the end of the array.
>>
>> Or I must use something as this :
>>
>> index := 0
>> if index > array length
>> index =:  1
>> else
>> index := index + 1
>>
>>
>> and then read the number with array at: index
>>
>> Roelof
>>
>>
>> Op 3-12-2018 om 10:08 schreef Richard O'Keefe:
>>
>> Roelof Wobben wrote
>> "I have to reread the file till the adding causes the same outcome  as
>> we had already"
>> You have to process the *sequence of changes* repeatedly;
>> you DON't have to *reread the file*.  Somebody already made this point.
>> Having read the changes into an array, you can iterate repeatedly over
>> that array.
>>
>> to find the first repeated frequency given a sequence of changes
>> make an empty Set to hold the sums that have been seen so far.
>> set the frequency to 0.
>> loop forever
>> for each change in the changes
>> increment the frequency by the change.
>> if the frequency is in the set
>> return the frequency
>>otherwise add the frequency to the set.
>>
>>  partTwo: aFileName
>> Transcript print: (self firstRepeatedFrequency: (self changesFrom:
>> aFileName)); cr; flush.
>>
>> On Mon, 3 Dec 2018 at 19:31, Roelof Wobben  wrote:
>>
>>> Thanks,
>>>
>>> For the second I have to take a good look.
>>>
>>> I have to reread the file till the adding causes the same outcome  as we
>>> had already
>>>
>>> so for example if we have the sequence :
>>>
>>> +3, +3, +4, -2, -4
>>>
>>> it has as outcome :
>>>
>>> 3 6 10 8 4
>>>
>>> so no outcome is there a second time so we repeat the sequence
>>>
>>>
>>> 7 10
>>>
>>> the 10 shows up a second time so there we have our answer.
>>>
>>>
>>> Roelof
>>>
>>>
>>>
>>> Op 3-12-2018 om 03:45 schreef Richard O'Keefe:
>>>
>>> The key question is "what do you mean by improve"?
>>> I'd start by asking "what are you doing that you will still have to do in
>>> part 2, and what won't you do?"  So looking at part 2, you will want to
>>> convert the lines to integers, and
>>>   input := Array streamContents: [:lines |
>>> 'input.txt' asFileReference readStreamDo: [:in |
>>>   [in atEnd] whileFalse: [lines nextPut: in nextLine asInteger]]].
>>> gives you a chunk of code you can use in both parts.  So you might
>>> want to have
>>>
>>> Day1
>>>   changesFrom: aFileName
>>> ^Array streamContents: [:changes |
>>>   aFileName asFileReference readStreamDo: [:in |
>>> [in atEnd] whileFalse: [changes nextPut: in nextLine asInteger]]]
>>>   partOne: aFileName
>>> ^(self changesFrom: aFileName) sum
>>>   partTwo: aFileName
>>> ...
>>> The file name should not be wired in because you want some test files.
>>>
>>>
>>>
>>>
>>
--- End Message ---


Re: [Pharo-users] How to take care that the + before a number is ignored

2018-12-02 Thread phil--- via Pharo-users
--- Begin Message ---
I am not using a file, but copy/paste my puzzleInput into a puzzleInput
method.

Then I use lines from there.

e.g. shifts

^ self puzzleInput lines collect: [ :each | ((each beginsWith: '+')
ifTrue: [ each allButFirst ] ifFalse: [ each  ]) asNumber ]

Because the challenge is personalized and it is annoying to have to commit
a supplementary file in the github repository.


Phil

On Sun, Dec 2, 2018 at 3:27 PM Benoit St-Jean via Pharo-users <
pharo-users@lists.pharo.org> wrote:

> Exactly!
>
> It's easier to manipulate that OrderedCollection that to open/reopen the
> file.  It'll be VERY handy for problem #2 where you will need to iterate
> multiple times on the data!  ;)
>
> -
> Benoît St-Jean
> Yahoo! Messenger: bstjean
> Twitter: @BenLeChialeux
> Pinterest: benoitstjean
> Instagram: Chef_Benito
> IRC: lamneth
> Blogue: endormitoire.wordpress.com
> "A standpoint is an intellectual horizon of radius zero".  (A. Einstein)
>
>
> On Sunday, December 2, 2018, 7:15:06 a.m. EST, Roelof Wobben <
> r.wob...@home.nl> wrote:
>
>
> Op 2-12-2018 om 12:19 schreef Benoit St-Jean via Pharo-users:
>
>
> oke, and if I understand your code files is then the variable that holds
>
> the file.
>
> Roelof
>
>
>
--- End Message ---


Re: [Pharo-users] UFFI and opaque(ish) types

2018-11-30 Thread phil--- via Pharo-users
--- Begin Message ---
Inherit from FFIOpaqueObject

+ initialize TypeMap

I have a few here:

https://github.com/Pharophile/XmppTalk

https://github.com/Pharophile/XmppTalk/tree/master/packages/XmppTalk-ExternalStructures.package
https://github.com/Pharophile/XmppTalk/blob/master/packages/XmppTalk-LibStrophe.package/StropheLib.class/class/initializeTypeMap.st

HTH
Phil



On Fri, Nov 30, 2018 at 2:39 PM Alistair Grant 
wrote:

> How are opaque(ish) types normally handled in UFFI (or FFI)?
>
> E.g. if I want to use libstuff which defines the following structure:
>
> struct stuffstruct {
> typeA a;
> typeB b;
> } stufftype;
>
>
> I might know they're integers, but not the size, signed vs. unsigned,
> etc.
>
> The definitions of typeA and typeB are buried in multiple layers of
> header files, dependent on #if tests, can be different sizes on
> different platforms (e.g. Linux vs. MacOS), etc.?
>
> Is this documented somewhere?
>
> Thanks,
> Alistair
>
>
>
--- End Message ---