help / color / mirror / Atom feed
From: Ben Bacarisse <>
Subject: Re: project euler 26
Date: Sun, 10 Sep 2023 20:22:54 +0100	[thread overview]
Message-ID: <> (raw)
In-Reply-To: udjvoc$gv16$

"Dmitry A. Kazakov" <> writes:

> On 2023-09-10 03:20, Ben Bacarisse wrote:
>> "Dmitry A. Kazakov" <> writes:
>>> On 2023-09-09 02:25, Ben Bacarisse wrote:
>>>> "Dmitry A. Kazakov" <> writes:

>>>>> As I said you think in a wrong direction of abstracting the language
>>>>> "finding maximum" rather than the problem space, e.g. generalization to
>>>>> other bases, other mathematical structures etc.
>>>> Generalising to an arbitrary base is local to the function that finds
>>>> the answer for one element.  It's an entirely separate axis of
>>>> generalisation to that of where the elements come from.
>>>> It's interesting to me that you consider one simply wrong and the other
>>>> natural.
>>> Because one is a software design artifact and another is the result of
>>> problem space analysis.
>> Which one the wrong one?
> None automatically is. The point is avoiding overdesigning a numeric
> puzzle.

Ah, I thought your criticise was intended to be general -- that
"abstracting the language 'finding maximum' rather than the problem
space" was always wrong, but it seems you meant only in the case of a
puzzle like this.  Numeric puzzles like this should only be generalised
in a few "approved" directions?

Obviously I disagree.  I would probably not bother doing this sort of
puzzle if it did not spark thoughts that go well beyond getting the
answer and a few obvious variation like using a different base.

Because I am interested in programming languages in general I always
solve such puzzles in more than one language so I can see how well they
express the algorithms involved.

Since prime numbers are crucial here, I had already tried a couple of
prime sieves in one of my solutions.  In that Ada solution, I would
probably have to store the primes somewhere and maximise over that.
That's what got me thinking about a general "maximise F over X" function
because if Ada had a simple way to do that, I could try various ways to
write the sieve -- the primes might end up in an array, a set or a map,
and it would make no difference to the rest of the code.

But the conclusion seems to be that maximising over any container is
just too simple to be worth making it a reusable component in Ada.  And
even then it would not (as far as I can tell) work for native arrays.

> [...]
>> This is probably the closest we can get to a universal solution.
>> Vectors don't have a Key function but I am sure I could find out what
>> should be provided there.
> Vector has To_Index for Key.
> In general, note that Ada does not require you to use any library. I
> personally dislike cursors in particular because of their "functional"
> style. I prefer plain element position and loop iteration of ordered
> structures. A container library based on this paradigm would use other
> generic abstraction.
> Furthermore, I prefer dynamic polymorphism of tagged types over parametric
> one of generics. Therefore to me Maximum_At should rather be a class-wide
> or primitive operation than a generic.

I was looking for whatever design you thought best, since you know Ada
infinitely better that I do.  It would be a shame if something I said
has ended up causing you to propose solutions you don't think are the
best ones for this example.

> In Ada you have freedom to choose your way, which also massively reduces
> universality of any abstraction, which will never apply universally.

That's a strange remark.  You have to do things the Ada way.  The
freedom is only in choosing how to combine the specific tools in Ada's
toolbox, and Ada also constrains how the tools can be combined.  This is
true for any programming language.  None of then give you the freedom
choose your way unless your way already aligns with what it permitted!

> I would like to have means to deal with this problem by means of ad-hoc
> supertypes, but that will never happen due to lack of interest in reworking
> the language type system and because in "Dark Ages" there is virtually no
> research on fundamental language construction topics.

I don't believe that to be the case.  I can believe that there is little
research into overhauling Ada's type system, but not in general.


  reply	other threads:[~2023-09-10 19:22 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-04  9:19 project euler 26 CSYH (QAQ)
2023-09-04 11:06 ` Niklas Holsti
2023-09-04 12:39   ` Dmitry A. Kazakov
2023-09-04 16:01     ` Ben Bacarisse
2023-09-04 19:20       ` Dmitry A. Kazakov
2023-09-04 20:18         ` Ben Bacarisse
2023-09-04 21:00           ` Dmitry A. Kazakov
2023-09-04 23:16             ` Ben Bacarisse
2023-09-05  7:23               ` Dmitry A. Kazakov
2023-09-05 15:18                 ` Ben Bacarisse
2023-09-05 17:08                   ` Dmitry A. Kazakov
2023-09-06  1:10                     ` Ben Bacarisse
2023-09-06  7:06                       ` Dmitry A. Kazakov
2023-09-06 15:16                         ` Ben Bacarisse
2023-09-06 15:54                           ` Dmitry A. Kazakov
2023-09-06 23:32                             ` Ben Bacarisse
2023-09-07  9:02                               ` Dmitry A. Kazakov
2023-09-08  1:32                                 ` Ben Bacarisse
2023-09-08  7:23                                   ` Dmitry A. Kazakov
2023-09-09  0:25                                     ` Ben Bacarisse
2023-09-09  9:32                                       ` Dmitry A. Kazakov
2023-09-10  1:20                                         ` Ben Bacarisse
2023-09-10  8:46                                           ` Dmitry A. Kazakov
2023-09-10 19:22                                             ` Ben Bacarisse [this message]
2023-09-11  6:53                                               ` Dmitry A. Kazakov
2023-09-11 16:13                                                 ` Ben Bacarisse
2023-09-12  7:17                                                   ` Dmitry A. Kazakov
2023-09-13 12:24                                                     ` Ben Bacarisse
2023-09-14  6:33                                                       ` Dmitry A. Kazakov
2023-09-14 14:30                                                         ` Ben Bacarisse
2023-09-08  6:09                               ` G.B.
2023-09-08 21:02                                 ` Ben Bacarisse
2023-09-09  8:13                                   ` G.B.
2023-09-09 21:04                                     ` Ben Bacarisse
2023-09-10  9:11                                     ` Dmitry A. Kazakov
2023-09-05 17:35                 ` moi
2023-09-04 14:23 ` Dmitry A. Kazakov
2023-09-07  7:31 ` Francesc Rocher
2023-09-15  9:07   ` CSYH (QAQ)
2023-09-19  7:59     ` comp.lang.ada
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox