Discussion:
Permutation generator in ada library
(too old to reply)
Stribor40
2014-10-03 00:36:28 UTC
Permalink
Does ada have built in function that guven integer N creates all possible permutations.
I found this code http://rosettacode.org/wiki/Permutations#The_generic_package_Generic_Perm
but was wondering if i can just call Ada built in function?
Stribor40
2014-10-03 04:01:57 UTC
Permalink
in the post above there is package that generates these permutations....

I have saved 3 files....in same order as the files are in posting
Generic_Perm.ads Generic_Perm.adb Print_Perms.adb

when i try to compile....gnatmake Print_Perms.adb I get error...

Generic_Perm.adb:1:14: file "generic_perm.ads" not found
gnatmake: "Generic_Perm.adb" compilation error

What am i doing wrong?
AdaMagica
2014-10-03 04:34:34 UTC
Permalink
Generic_Perm.ads Generic_Perm.adb Print_Perms.adb
Generic_Perm.adb:1:14: file "generic_perm.ads" not found
gnatmake: "Generic_Perm.adb" compilation error
Use lower case for file names.
Stribor40
2014-10-03 04:47:37 UTC
Permalink
Post by AdaMagica
Generic_Perm.ads Generic_Perm.adb Print_Perms.adb
Generic_Perm.adb:1:14: file "generic_perm.ads" not found
gnatmake: "Generic_Perm.adb" compilation error
Use lower case for file names.
ok that worked thanks.....didnt know need to be lower cases
Shark8
2014-10-03 19:32:52 UTC
Permalink
Post by Stribor40
Post by AdaMagica
Generic_Perm.ads Generic_Perm.adb Print_Perms.adb
Generic_Perm.adb:1:14: file "generic_perm.ads" not found
gnatmake: "Generic_Perm.adb" compilation error
Use lower case for file names.
ok that worked thanks.....didnt know need to be lower cases
It doesn't, at least not technically.
The real reason they tell you to use lowercase is that GNAT on the
case-sensitive OSes can't tell if SomeThing.ads and/or something.ads is
supposed to be associated with package SOMETHING. -- Incidentally, this
would be a non issue in a compiler/environment that had the `83-style
library.
Simon Wright
2014-10-03 20:47:25 UTC
Permalink
Incidentally, this would be a non issue in a compiler/environment that
had the 83-style library.
I remember really annoying problems with DEC Ada and its library
implementation. Quite easy to botch it up to the point where the
solution was to wipe the lot and restart.
Shark8
2014-10-04 03:01:03 UTC
Permalink
Post by Simon Wright
Incidentally, this would be a non issue in a compiler/environment that
had the 83-style library.
I remember really annoying problems with DEC Ada and its library
implementation. Quite easy to botch it up to the point where the
solution was to wipe the lot and restart.
Really?
I'd be quite interested in hearing more.
Simon Wright
2014-10-04 07:05:47 UTC
Permalink
Post by Shark8
Post by Simon Wright
Incidentally, this would be a non issue in a compiler/environment that
had the 83-style library.
I remember really annoying problems with DEC Ada and its library
implementation. Quite easy to botch it up to the point where the
solution was to wipe the lot and restart.
Really?
I'd be quite interested in hearing more.
This was quite some time ago :-)

Maybe saying "I remember" was a bit of an exaggeration. I recall the
annoyance, but not what I did to bring it about. Sorry.
Randy Brukardt
2014-10-09 22:29:59 UTC
Permalink
Post by Simon Wright
Incidentally, this would be a non issue in a compiler/environment that
had the 83-style library.
I remember really annoying problems with DEC Ada and its library
implementation. Quite easy to botch it up to the point where the
solution was to wipe the lot and restart.
Right, that's the problem with such schemes. The Janus/Ada project manager
has similar issues occassionally (and you have to wipe it when you get a new
compiler). It's easy enough to rebuild, though (and I have some ways to make
it even easier on the to-do list).

Randy.
Stribor40
2014-10-03 04:51:08 UTC
Permalink
Is there Ada library for this .....

Code from that link gives wrong output...lets say for 3 gives..

1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
3 2 1 <- this shouldnt be there??
Niklas Holsti
2014-10-03 06:28:35 UTC
Permalink
Post by Stribor40
Is there Ada library for this .....
Code from that link gives wrong output...lets say for 3 gives..
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
3 2 1 <- this shouldnt be there??
Right. The author of this program has confused herself with the
"Is_Last" output parameters of the procedures, and has not documented
them properly. They work differently for the two procedures:

- Generic_Perm.Set_First returns Is_Last = True when the permutation it
PRODUCES is the last one (that is, when N = 1).

- Generic_Perm.Go_To_Next returns Is_Last = True when the permutation it
is GIVEN is the last one, and it does not produce a new permutation in
that case.

The loop in Print_Perms consequently should have a more complex form,
for example like this:

Perms.Set_To_First(P, Done);
Print (P);
if not Done then
-- There is more than one permutation, print them:
loop
Perms.Go_To_Next(P, Done);
exit when Done;
-- There was a next permutation, print it:
Print(P);
end loop;
end if;
--
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
. @ .
Stribor40
2014-10-03 10:10:27 UTC
Permalink
Is there Ada function for this?
Simon Wright
2014-10-03 11:13:49 UTC
Permalink
Post by Stribor40
Is there Ada function for this?
Well, you just found one, so obviously there is.

If you mean, is there one in the standard library, then the answer is No
(as you can see by checking out the online Ada Reference manual at
http://www.ada-auth.org/standards/12rm/html/RM-TOC.html - look for Annex
A and following).
Niklas Holsti
2014-10-03 04:36:04 UTC
Permalink
Post by Stribor40
in the post above there is package that generates these permutations....
I have saved 3 files....in same order as the files are in posting
Generic_Perm.ads Generic_Perm.adb Print_Perms.adb
when i try to compile....gnatmake Print_Perms.adb I get error...
Generic_Perm.adb:1:14: file "generic_perm.ads" not found
gnatmake: "Generic_Perm.adb" compilation error
What am i doing wrong?
No idea, it should work like that, at least if you are on MS Windows,
where letter case does not matter in file names. (GNAT convention is to
use lower-case file names, and there is seldom reason not to follow that
convention.)

The error you get is really strange; when GNAT compiles Print_Perms.adb,
the "with" statement for package Generic_Perm should make GNAT find and
process Generic_Perm.ads before it even tries to process Generic_Perm.adb.

Did you put all three files in the same folder? Are they still there?
--
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
. @ .
Stribor40
2014-10-03 04:42:24 UTC
Permalink
can i email you ziped folder of the 3 files?
Brian Drummond
2014-10-03 11:00:34 UTC
Permalink
Post by Stribor40
in the post above there is package that generates these permutations....
I have saved 3 files....in same order as the files are in posting
Generic_Perm.ads Generic_Perm.adb Print_Perms.adb
when i try to compile....gnatmake Print_Perms.adb I get error...
"Generic_Perm.adb" compilation error
What am i doing wrong?
Gnat for some reason lower-cases the filenames when generating them from
the package names.

On Linux, the filenames Generic_Perm.ads and generic_perm.ads actually
refer to different files, and the second of these is apparently missing.
Rename the files and all will be well (or at least better!)

- Brian
Niklas Holsti
2014-10-03 16:08:35 UTC
Permalink
Post by Brian Drummond
Post by Stribor40
in the post above there is package that generates these permutations....
I have saved 3 files....in same order as the files are in posting
Generic_Perm.ads Generic_Perm.adb Print_Perms.adb
when i try to compile....gnatmake Print_Perms.adb I get error...
"Generic_Perm.adb" compilation error
What am i doing wrong?
Gnat for some reason lower-cases the filenames when generating them from
the package names.
The reason is IMO clear: package names are case-insensitive in Ada, so
the context clauses "with PKG" and "with Pkg" refer to the same package.
If you want to generate case-sensitive file names from package names,
the case distinction must be suppressed, so the reasonable choices are
all-upper-case or all-lower-case, with the lower-case alternative
clearly preferable as few people keep their Caps-Lock on.
Post by Brian Drummond
On Linux, the filenames Generic_Perm.ads and generic_perm.ads actually
refer to different files
Yes, but the weird thing is that the error message Stribor40 quotes
shows that GNAT is compiling the generic package body in
Generic_Perm.adb, but cannot find the declaration in generic_perm.ads.
Oh well, I understood it is working with lower-case names, so...

(OMG, fiddling with this question made me realise that Mac OS-X uses, by
default, case-insensitive file names, although it is otherwise
Unix-type. Funny things happen, for example the command "mv -i aaa AAA"
asks me if I want to "overwrite AAA? (y/n [n])" - but there is no AAA...)
--
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
. @ .
Björn Lundin
2014-10-03 16:57:39 UTC
Permalink
Post by Niklas Holsti
(OMG, fiddling with this question made me realise that Mac OS-X uses, by
default, case-insensitive file names, although it is otherwise
Unix-type. Funny things happen, for example the command "mv -i aaa AAA"
asks me if I want to "overwrite AAA? (y/n [n])" - but there is no AAA...)
It's because they call it 'case-preserving'.
But it's not really mac-os, its the file system hfs+.
If you format a drive as udf (I think it's called) you get a
case-sensitive file systems, even on a mac.
very confusing ...


--
Björn
j***@peppermind.com
2014-10-03 12:54:30 UTC
Permalink
Post by Stribor40
Does ada have built in function that guven integer N creates all possible permutations.
I have a package that generates the n-th permutation but it's not online. Drop a note to john-"at"-peppermind.com if you're interested.
j***@gmail.com
2014-10-03 18:50:30 UTC
Permalink
Post by Stribor40
Does ada have built in function that guven integer N creates all possible permutations.
I found this code http://rosettacode.org/wiki/Permutations#The_generic_package_Generic_Perm
but was wondering if i can just call Ada built in function?
I can address the original issue about permutation-generating Ada.
From my pack-rat days, I'm aware of three implementations that might
serve.

One is contained in the library Charles built by Matthew Heany
http://home.earthlink.net/~matthewjheaney/charles/index.html

His last update was in 2004. The materials are at
http://charles.tigris.org/source/browse/charles/src/

--

The second is by Mats Weber. My copy carries dates to 1990.
Mats Weber's Ada Component Library, version 2.0
http://mats.weber.org/ada/mw_components.html

His document says
Copyright (c) 1999 Mats Weber, Ch. du Grillon 10, 1007 Lausanne, Switzerland.
These components were originally developed by Mats Weber at EPFL
(Swiss Federal Institute of Technology, Computer Science Theory
Laboratory and Software Engineering Laboratory) from 1985 to 1990

They carry the GNU General Public License
--
My oldest holding is an archeological remnant from Simtel 20, built by
Doug Bryan.

"This software is released to the Public Domain" but I don't know
where there is a public copy. I'd be happy to share with anyone
interested. ***@gmail.com


-- Unit name : Permutations_Class
-- Version : 1.0
-- Author : Doug Bryan
-- : Computer Systems Lab
-- : Stanford University
-- : Stanford CA, 94305
-- DDN Address : ***@su-sierra
-- Copyright : (c) -none-
-- Date created : 15 April 1985
-- Release date : 15 April 1985
-- Last update : 15 April 1985
-- Machine/System Compiled/Run on : DG MV/10000 ADE 2.2

generic
type Item_Type is private;
type Index_Type is (<>);
type List_Type is array (Index_Type range <>) of Item_Type;
package Permutations_Class is

generic
with procedure Process (A_Permutation : List_Type);
procedure Iterate_Through_Length_Factorial_Permutations
(Of_Items : List_Type);

-- For an actual parameter for Of_Items of length n, n! (n factorial)
-- permutations will be produced.

-- The procedure permutes the elements in the array ITEMS.
-- actually it permutes their indicies and re-arranges the items
-- within the list. The procedure does not care of any or all
-- of the items in the list are equal (the same).

end Permutations_Class;

John
Dirk Craeynest
2014-10-04 18:06:58 UTC
Permalink
The code by Doug Bryan, that John mentions at the end of his posting,
was included in the "Ada and Software Engineering Library Version 2
(ASE2)".

Numerous versions of the ASE library were put together by Richard
Conn, the last one in October 2000. They were typically distributed
on CDROM at the time, among others at various Ada events such as ACM
SIGAda and Ada-Belgium conferences.

The last ASE2 version is still available on the Ada-Belgium site:
ftp://ftp.cs.kuleuven.be/pub/Ada-Belgium/ase/index.htm

The s.c. "asset" that includes the Permutations_Class package is at:
ftp://ftp.cs.kuleuven.be/pub/Ada-Belgium/ase/support/cardcatx/csparts.htm

The relevant source code is included in the files CSPARTS.SRC and
CSPARTB2.SRC in the csparts.zip archive, retrievable via the above URL.

Enjoy... ;-)

Dirk
***@cs.kuleuven.be (for Ada-Belgium/Ada-Europe/SIGAda/WG9)

*** 20th Intl.Conf.on Reliable Software Technologies - Ada-Europe'2015
*** June 22-26, 2015 **** Madrid, Spain **** http://www.ada-europe.org


= Newsgroups: comp.lang.ada
= Date: Fri, 3 Oct 2014 11:50:30 -0700 (PDT)
= Subject: Re: Permutation generator in ada library
= From: ***@gmail.com
=
[...]
=
= I can address the original issue about permutation-generating Ada.
= >From my pack-rat days, I'm aware of three implementations that might
= serve.
=
[...]
=
= My oldest holding is an archeological remnant from Simtel 20, built by
= Doug Bryan.
=
= "This software is released to the Public Domain" but I don't know
= where there is a public copy. I'd be happy to share with anyone
= interested. ***@gmail.com
=
=
= -- Unit name : Permutations_Class
= -- Version : 1.0
= -- Author : Doug Bryan
= -- : Computer Systems Lab
= -- : Stanford University
= -- : Stanford CA, 94305
= -- DDN Address : ***@su-sierra
= -- Copyright : (c) -none-
= -- Date created : 15 April 1985
= -- Release date : 15 April 1985
= -- Last update : 15 April 1985
= -- Machine/System Compiled/Run on : DG MV/10000 ADE 2.2
=
= generic
= type Item_Type is private;
= type Index_Type is (<>);
= type List_Type is array (Index_Type range <>) of Item_Type;
= package Permutations_Class is
=
= generic
= with procedure Process (A_Permutation : List_Type);
= procedure Iterate_Through_Length_Factorial_Permutations
= (Of_Items : List_Type);
=
= -- For an actual parameter for Of_Items of length n, n! (n factorial)
= -- permutations will be produced.
=
= -- The procedure permutes the elements in the array ITEMS.
= -- actually it permutes their indicies and re-arranges the items
= -- within the list. The procedure does not care of any or all
= -- of the items in the list are equal (the same).
=
= end Permutations_Class;
=
= John
Randy Brukardt
2014-10-09 22:37:17 UTC
Permalink
"Dirk Craeynest" <***@feles.cs.kuleuven.be.> wrote in message news:m0pd02$hip$***@dont-email.me...
...
Post by Dirk Craeynest
ftp://ftp.cs.kuleuven.be/pub/Ada-Belgium/ase/index.htm
It's also available in the AdaIC archives:
http://archive.adaic.com/ase/

It seemed valuable to have multiple copies out there, so I put one up a few
years ago after Richard Conn's site disappeared. I think I copied Dirk's
version, so they're likely the same.

Randy.

Loading...