expect procedure name in procedure call(newbie)

ada

    Next

  • 1. How unchecked conversion works?
    HI! I'd like to know what the compiler do for represent a simple float for example 34,4 delta 0.1 into an integer type for example range 1..10 using an unchecked_conversion. Thanks!
  • 2. Will the World ever see something beyond GNAT 3.15p?
    What ever happend to this whole concept of a free Ada compiler? ACT has not released a public version for what over two years now? It seems like ACT went the "drug dealer" route, get them addicted by feeding them free dope and then start bleeding them. What's a one person ACT "maintenance" license go for these days >4K, please!!!! Well anyway, this ought to kick up some dust. William J. Thomas

expect procedure name in procedure call(newbie)

Postby R » Thu, 30 Dec 2004 19:37:03 GMT

Hello.

I've got 'expect procedure name in procedure call' warning but
I think my code is good
Inside testclass.adb I have Create function and when I'm trying to call
it from
main.adb unit I receive that error.

Below are full codes of my Ada units.

And by the way - how can I dynamically allocate memory for e.g. 10
elements(array of Floats)?
How can I reallocate them to 20 elements or 4?
How can I free the memory?

thanks in advance
best regards R

Codes:

main.adb:
--------
with testclass;
procedure Main is
object : testclass.rec1_Access;
begin
testclass.Create(object, 10);
end Main;

testclass.ads:
--------------
package testclass is
type rec1 is tagged private;
type rec1_Access is access rec1;
function Create(this: rec1_Access; s: Integer) return Integer;
private
type rec1 is tagged record
field: Integer;
end record;
end testclass;

testclass.adb:
--------------
package body testclass is
function Create(this: rec1_Access; s: Integer) return Integer is
begin
this.field :=s;
		return this.field;
	end Create;
end testclass;


Re: expect procedure name in procedure call(newbie)

Postby Florian Weimer » Thu, 30 Dec 2004 21:07:30 GMT

> testclass.Create(object, 10);

You are ignoring the return value of Create, which is not allowed.

Re: expect procedure name in procedure call(newbie)

Postby Martin Dowie » Thu, 30 Dec 2004 21:32:09 GMT



In Ada you don't need to play around with memory 
allocation/reallocation/deallocation as much in other lower level 
languages. If you know in advance the maximum number you are going to 
have then you could use a discriminated array, e.g.

    type Number_Of_Floats is range 0 .. 20;
    --  Never going to be more than 20.

    type Array_Of_Floats is array (Number_Of_Floats range <>) of Float;

    type Group_Of_Floats (Length : Number_Of_Floats := 0) is record
       F : Array_Of_Floats (1 .. Length);
    end record;

    My_Floats : Group_Of_Floats;
begin
    ...

If you really don't know the number of items you are going to have then 
use one of the many container libraries available - you wouldn't 
re-invent the wheel and re-code the STL if you were using C++ would you?

Here is a link to a page of such libraries:

 http://www.**--****.com/ +Libraries

Look under "Data Types".

Cheers

-- Martin

Re: expect procedure name in procedure call(newbie)

Postby Martin Dowie » Thu, 30 Dec 2004 21:34:35 GMT



Typo - that should be a "discriminated record".

Re: expect procedure name in procedure call(newbie)

Postby R » Thu, 30 Dec 2004 22:03:24 GMT

OK so i added new variable ret(Integer) and added:
ret := testclass.Create(object, 10);

but now Create raises an expception: CONSTRAINT_ERROR : testclass.adb:5
access check failed

where the Create looks like:
function Create(this: rec1_Access; s: Integer) return Integer is
begin
this.field := s; -- this is the 5th line - access check error
return this.field;
end Create;

basicly  the codes are the same from my first post - I only folow Your
instuction not to ignore the return value.

Is my access type wrong? it point to rec1 tagged record.
thanks in advance for Your help
best regards R


Re: expect procedure name in procedure call(newbie)

Postby Mark Lorenzen » Thu, 30 Dec 2004 22:24:45 GMT

"R" < XXXX@XXXXX.COM > writes:


The parameter 'this' is of an access type. As the actual parameter you
pass a non-initialised variable. In Ada, all variables of access type
have the value 'null' by default. So you pass 'Create' a null value
and the dereference it.

Your example seems to be a translation of a C++ function. I would do
the following instead:

1) Make 'Create' a procedure instead of a function with the following
   signature:

   Create (This : out Rec1; S : in Integer);

2) procedure Main is
     Object : Testclass.Rec1;
   begin
     Testclass.Create(Object, 10);
   end Main;

Do not fiddle around with pointers as much as you do. It seems like
you try to program in Ada the C++ way.

- Mark Lorenzen

Re: expect procedure name in procedure call(newbie)

Postby Martin Krischik » Fri, 31 Dec 2004 03:46:49 GMT




If you learn for Hobby then I  suggest a container lib with support for
indefinite object:

 http://www.**--****.com/ :Ada:Libraries:MultiPurpose:AdaCL#Components.

If not you have to do it the hard way:

 http://www.**--****.com/ :Ada:Types:access


You call the parameter this - but Create is a "static" method. Read:

 http://www.**--****.com/ :Ada:OO#Primitive_operations


your are aware that this is null?


-- 
mailto:// XXXX@XXXXX.COM 
 http://www.**--****.com/ 

Similar Threads:

1.Reply: expect procedure name in procedure call(newbie)

You are calling a function as though it were a procedure.  This is
alright in C and C++, where the result is just silently thrown away,
but in Ada you have to do something with the result, such as assign it
or use it in a subsequent expression or routine call.

2.calling non-PURE procedures in PURE procedures

In Fortran 95, a PURE procedure cannot call an intrinsic FUNCTION or
SUBOUTINE that is not PURE. The non-PURE instrinsic procedures I know
of are

DATE_AND_TIME
SYSTEM_CLOCK
RANDOM_NUMBER
RANDOM_SEED

Are there others?

Lahey/Fujitsu Fortran 95 does not catch the error of non_PURE
intrinsic functions in PURE procedures, nor did earlier versions of
Compaq Visual Fortran, but CVF 6.6C DOES catch the error. I found some
bugs in my code when upgrading from CVF 6.6 to CVF 6.6C.

The code below, saved in "nonpure.f", compiles without error for LF95
but not CVF 6.6C (which is the correct behavior).

LF95 compilation:
lf95 -c -nfix -f95 -nco nonpure.f
Lahey/Fujitsu Fortran 95 Express Release 5.70c                 
Compiling program unit nonpure_module at line 1:
Encountered 0 errors, 0 warnings in file nonpure.f.
Compiling file nonpure.f.

CVF compilation:
df -c -free -stand:f95 nonpure.f
Compaq Visual Fortran Optimizing Compiler Version 6.6 (Update C)
Copyright 2003 Compaq Computer Corp. All rights reserved.

nonpure.f
nonpure.f(7) : Error: Any procedure referenced in a PURE procedure,
including one referenced via a defined operation or assignmnent, must
be explicitly declared PURE.   [DATE_AND_TIME]
call date_and_time(xdate)
-----^
nonpure.f(12) : Error: Any procedure referenced in a PURE procedure,
including one referenced via a defined operation or assignmnent, must
be explicitly declared PURE.   [RANDOM_NUMBER]
call random_number(x)
-----^
nonpure.f(16) : Error: Any procedure referenced in a PURE procedure,
including one referenced via a defined operation or assignmnent, must
be explicitly declared PURE.   [RANDOM_SEED]
call random_seed()
-----^
nonpure.f(21) : Error: Any procedure referenced in a PURE procedure,
including one referenced via a defined operation or assignmnent, must
be explicitly declared PURE.   [SYSTEM_CLOCK]
call system_clock(ic)
-----^

! begin file nonpure.f
module nonpure_module
implicit none
contains
!
pure subroutine xdate_and_time()
character (len=8) :: xdate
call date_and_time(xdate)
end subroutine xdate_and_time
!
pure subroutine xrandom_number()
real :: x
call random_number(x)
end subroutine xrandom_number
!
pure subroutine xrandom_seed()
call random_seed()
end subroutine xrandom_seed
!
pure subroutine xsystem_clock()
integer :: ic
call system_clock(ic)
end subroutine xsystem_clock
end module nonpure_module

3.How to make a procedure call from another procedure

It is really simple:

proc example {} {puts "hello!"}

proc test {procname} {
   $procname
}
% test example
hello!

4.How to make a procedure call from another procedure

Hi,

I am new to Tcl/Tk and have a little prob. I have to make a procedure
call (within another procedure).The name of the procedure is stored in
a variable and it doesn't take any arguments. To be more clear, I have
a variable "procName" which stores the name of the procedure and I have
to call this procedure from another procedure say, "Proc1". I tried
writing
$procName
within the procedure "Proc1" but this does not make a call to the
specified procedure. How should I go about it?

Regards
-RG

5.Expect - hangs when called from a nested procedure.

Running Active Tcl 8.4.14 on Windows  XP.

Are there any known issues with Expect when called from a 2 level
nested procedure?  I have an FTP Expect script that hangs when the
calling script is moved to a procedure.

E.G  This works - top level script calls dialog procedure(see below
for dialog proc details.


expectFTP,tcl

    .................
    .................
    set variables
    spawn ftp $host

    set prompt     "(Name|login|Login|Username|User).*:.*"
    set sendString "$user1"

    # call diaglog proc
    dialog $spawn_id $prompt $sendString

    #set prompt     "Password:"
    set sendString "$userpassword1"

    #call dialog proc
    dialog $spawn_id $prompt $sendString


E.G  This fails - top level script calls expectFTP_proc procedure
which calls dialog proc details.  The "spawn" creates the FTP
connection, identifies the "User" prompt and submits the "userid" send
string but then the script hangs on "Password".  The debug output
indicates that there is no response from the "userid" send so the FTP
server waits for the userid while Expects looks for the password
prompt.

This only occurs when the code that calls dialog.proc is moved from
the top level script into a procedure.

I can email the complete script is anyone is interested .

Thanks.

Patrick.



expectFTP,tcl

    .................
    .................
    set variables

    # call expectFTP_proc

    expectFTP_proc

        set variables

        spawn ftp $host

        set prompt     "(Name|login|Login|Username|User).*:.*"
        set sendString "$user1"

        # call diaglog proc
        dialog $spawn_id $prompt $sendString

        #set prompt     "Password:"
        set sendString "$userpassword1"

        #call dialog proc
        dialog $spawn_id $prompt $sendString


==================================================

proc dialog { ftpSpawnId prompt sendString } {

    global ftpErrorMatch

    puts \n
    puts "spawnid         is $ftpSpawnId"
    puts "expected prompt is $prompt"
    puts "sendString      is $sendString"

    exp_log_user 1

    expect {

         -i $ftpSpawnId

         -re $prompt {
                puts "matched on prompt"
                exp_send      "$sendString\r"
                exp_send_user "$sendString\n"
         }

         "Unknown host" {
                puts "ERROR: Unknown host"
                expect *
                error "Expected: '$prompt'. Saw: $expect_out(buffer)"
         }


         $ftpErrorMatch {
                    puts "ERROR: FTP Error"
                    expect *
                    error "Expected: '$prompt'. Saw:
$expect_out(buffer)"
             }

         timeout {
                puts "ERROR: timeout exceeded"
                expect *
                error "Expected: '$prompt'. Saw: $expect_out(buffer)"
         }

         eof {
                expect *
                error "Expected: '$prompt'. Saw: $expect_out(buffer)"
         }
    }

    return [ array get expect_out ]

}

6. How to create a procedure that takes another procedure with an argument

7. procedure as argument in procedure

8. Nested procedures and procedure parameters



Return to ada

 

Who is online

Users browsing this forum: No registered users and 21 guest