1. type checking ?

Suppose you have a function/procedure and one of its

parameters is a sequence.

How can you type check the parameter to be a CONSTANT SEQUENCE NAME.


Bernie

My files in archive:
WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API 

Can be downloaded here:
http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan

new topic     » topic index » view message » categorize

2. Re: type checking ?

Bernie Ryan wrote:
> 
> Suppose you have a function/procedure and one of its
> parameters is a sequence.
> 
> How can you type check the parameter to be a CONSTANT SEQUENCE NAME.

Could you elaborate on what you mean by "CONSTANT SEQUENCE NAME?" This
sounds like you want the parameter to be a specific value.  If this is
accurate, then I can't see the utility of this, but here's an example:
with type_check
type my_constant_sequence_name( object m )
    return equal( m, "My Constant Sequence Name" )
end type

procedure foo( my_constant_sequence_name bar )
    -- ...
end procedure
foo("My Constant Sequence Name")  -- works
foo("Ha Ha!")                     -- fails


Matt

new topic     » goto parent     » topic index » view message » categorize

3. Re: type checking ?

Matt Lewis wrote:
> 
> Bernie Ryan wrote:
> > 
> > Suppose you have a function/procedure and one of its
> > parameters is a sequence.
> > 
> > How can you type check the parameter to be a CONSTANT SEQUENCE NAME.
> 
> Could you elaborate on what you mean by "CONSTANT SEQUENCE NAME?" This
> sounds like you want the parameter to be a specific value.  If this is
> accurate, then I can't see the utility of this, but here's an example:
> }}}
<eucode>
> with type_check
> type my_constant_sequence_name( object m )
>     return equal( m, "My Constant Sequence Name" )
> end type
> 
> procedure foo( my_constant_sequence_name bar )
>     -- ...
> end procedure
> foo("My Constant Sequence Name")  -- works
> foo("Ha Ha!")                     -- fails
> </eucode>
{{{

> 

Matt:

constant
  MySEQ = {1,2,3,4,5,6,7,8,9}

procedure useit(sequence seq_name)
  -- do stuff.
end procedure

-- The user can enter this which is WRONG
useit("MySEQ")

-- Or the user can enter this is CORRECT
useit(MySEQ)

-- NOTE they are both sequences so procedure will accept either.

Bernie

My files in archive:
WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API 

Can be downloaded here:
http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan

new topic     » goto parent     » topic index » view message » categorize

4. Re: type checking ?

Bernie Ryan wrote:
> 
> > Bernie Ryan wrote:
> > > 
> > > Suppose you have a function/procedure and one of its
> > > parameters is a sequence.
> > > 
> > > How can you type check the parameter to be a CONSTANT SEQUENCE NAME.

> }}}
<eucode>
> constant
>   MySEQ = {1,2,3,4,5,6,7,8,9}
> 
> procedure useit(sequence seq_name)
>   -- do stuff.
> end procedure
> 
> -- The user can enter this which is WRONG
> useit("MySEQ")
> 
> -- Or the user can enter this is CORRECT
> useit(MySEQ)
> 
> -- NOTE they are both sequences so procedure will accept either.
> 
> </eucode>
{{{


Unfortunately, this hasn't cleared it up for me.  I guess that I have a
couple of responses.  If the passed value is incorrect, then you can
simply validate it using equal().  Also, if the only correct value is a
specific constant, then why pass it as a parameter at all?  That seems
to be just increasing typing for no benefit.

I suspect that there's something more to this that you haven't made clear
yet.  What is the effect of one being WRONG and the other CORRECT?

What about (in the above example):
useit({1,2,3,4,5,6,7,8,9})

Matt

new topic     » goto parent     » topic index » view message » categorize

5. Re: type checking ?

Matt Lewis wrote:
> 
> > }}}
<eucode>
> > constant
> >   MySEQ = {1,2,3,4,5,6,7,8,9}
> > 
> > procedure useit(sequence seq_name)
> >   -- do stuff.
> > end procedure
> > 
> > -- The user can enter this which is WRONG
> > useit("MySEQ")
> > 
> > -- Or the user can enter this is CORRECT
> > useit(MySEQ)
> > 
> > -- NOTE they are both sequences so procedure will accept either.
> > 
> > </eucode>
{{{

> 
> Unfortunately, this hasn't cleared it up for me.  I guess that I have a
> couple of responses.  If the passed value is incorrect, then you can
> simply validate it using equal().  Also, if the only correct value is a
> specific constant, then why pass it as a parameter at all?  That seems
> to be just increasing typing for no benefit.
> 
> I suspect that there's something more to this that you haven't made clear
> yet.  What is the effect of one being WRONG and the other CORRECT?
> 
> What about (in the above example):
> }}}
<eucode>
>     useit({1,2,3,4,5,6,7,8,9})
> </eucode>
{{{


Matt:

The useit() procedure will try to process the sequence weather it is

a constant name sequence or the actual constant sequence because they

depending how the user calls the procedure.

I do not know in advance what the constant sequence will be because it is

added by the user via include file. 

Of course if user passes the name as a sequence the procedure will crash. 

I will just have to spell it out in the users manual and

HOPE that they read it. 

Bernie

My files in archive:
WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API 

Can be downloaded here:
http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan

new topic     » goto parent     » topic index » view message » categorize

6. Re: type checking ?

Bernie Ryan wrote:
> 
> The useit() procedure will try to process the sequence weather it is
> a constant name sequence or the actual constant sequence because they
> depending how the user calls the procedure.
> I do not know in advance what the constant sequence will be because it is
> added by the user via include file. 
> Of course if user passes the name as a sequence the procedure will crash. 
> I will just have to spell it out in the users manual and
> HOPE that they read it. 

Ok, I give up.  I still have no clue what you're asking.

Matt

new topic     » goto parent     » topic index » view message » categorize

7. Re: type checking ?

Matt Lewis wrote:
> 
> Bernie Ryan wrote:
> > HOPE that they read it. 
> 
> Ok, I give up.  I still have no clue what you're asking.
LOL. As I read I too had some HOPE that someone could make some sense of it.

I'm going to go out on a limb though and guess what Bernie is after:
sequence valids
         valids={}

procedure init()
  while 1 do
    line = gets(fn)
    if atom(line) then exit end if
    valids = append(valids,line)
  end while
end procedure

type valid(object x)
  return find(x,valids)!=0
end type

procedure useit(valid s)
  -- do stuff.
end procedure


Best I can do, given the vague-ish clues...

HTH,
Pete

new topic     » goto parent     » topic index » view message » categorize

8. Re: type checking ?

Bernie Ryan wrote:
> The useit() procedure will try to process the sequence weather it is
> a constant name sequence or the actual constant sequence because they
> depending how the user calls the procedure.
> I do not know in advance what the constant sequence will be because it is
> added by the user via include file. 
> Of course if user passes the name as a sequence the procedure will crash. 
> I will just have to spell it out in the users manual and
> HOPE that they read it. 


I'm still trying to work out Bernie's issue but here's what I've got so far...

Bernie has a file that is something like this ...

------------ start of bernie's file
include userfileA.e

global function/procedure useit(sequence x)
 <some processing goes here>
end function/procedure

include userfileB.e
------------- end of file

And a user of Bernie's application must supply a couple of include files.

------ start of userfileA.e
global constant WhatEver = "some text"
------ end of  userfileA.e

------ start of userfileB.e
useit(WhatEver)
------ end of  userfileB.e

Now the problem is that Bernie want to make sure that in userfileB, the user
codes ...

   useit(WhatEver)

and never codes ...

   useit("WhatEver")

plus allow the user to code ...

   useit("any other text")


-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

new topic     » goto parent     » topic index » view message » categorize

9. Re: type checking ?

Derek Parnell wrote:
> 
> Bernie Ryan wrote:
> > The useit() procedure will try to process the sequence weather it is
> > a constant name sequence or the actual constant sequence because they
> > depending how the user calls the procedure.
> > I do not know in advance what the constant sequence will be because it is
> > added by the user via include file. 
> > Of course if user passes the name as a sequence the procedure will crash. 
> > I will just have to spell it out in the users manual and
> > HOPE that they read it. 
> 
> 
> I'm still trying to work out Bernie's issue but here's what I've got so far...
> 
> Bernie has a file that is something like this ...
> 
> ------------ start of bernie's file
> include userfileA.e
> 
> global function/procedure useit(sequence x)
>  <some processing goes here>
> end function/procedure
> 
> include userfileB.e
> ------------- end of file
> 
> And a user of Bernie's application must supply a couple of include files.
> 
> ------ start of userfileA.e
> global constant WhatEver = "some text"
> ------ end of  userfileA.e
> 
> ------ start of userfileB.e
> useit(WhatEver)
> ------ end of  userfileB.e
> 
> Now the problem is that Bernie want to make sure that in userfileB, the user
> codes ...
> 
>    useit(WhatEver)
> 
> and never codes ...
> 
>    useit("WhatEver")
> 


Derek:

   Thanks for explaining it.

   That is exactly what I mean.

   How can you be sure that a user enters the token WhatEver which

   represents a string constant and not the string "WhatEver"

Bernie

My files in archive:
WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API 

Can be downloaded here:
http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan

new topic     » goto parent     » topic index » view message » categorize

10. Re: type checking ?

Bernie Ryan wrote:
> 
> Derek Parnell wrote:
> > 
> > Bernie Ryan wrote:
> > > The useit() procedure will try to process the sequence weather it is
> > > a constant name sequence or the actual constant sequence because they
> > > depending how the user calls the procedure.
> > > I do not know in advance what the constant sequence will be because it is
> > > added by the user via include file. 
> > > Of course if user passes the name as a sequence the procedure will crash. 
> > > I will just have to spell it out in the users manual and
> > > HOPE that they read it. 
> > 
> > 
> > I'm still trying to work out Bernie's issue but here's what I've got so
> > far...
> > 
> > Bernie has a file that is something like this ...
> > 
> > ------------ start of bernie's file
> > include userfileA.e
> > 
> > global function/procedure useit(sequence x)
> >  <some processing goes here>
> > end function/procedure
> > 
> > include userfileB.e
> > ------------- end of file
> > 
> > And a user of Bernie's application must supply a couple of include files.
> > 
> > ------ start of userfileA.e
> > global constant WhatEver = "some text"
> > ------ end of  userfileA.e
> > 
> > ------ start of userfileB.e
> > useit(WhatEver)
> > ------ end of  userfileB.e
> > 
> > Now the problem is that Bernie want to make sure that in userfileB, the user
> > codes ...
> > 
> >    useit(WhatEver)
> > 
> > and never codes ...
> > 
> >    useit("WhatEver")
> > 
> 
> Derek:
> 
>    Thanks for explaining it.
> 
>    That is exactly what I mean.
> 
>    How can you be sure that a user enters the token WhatEver which
> 
>    represents a string constant and not the string "WhatEver"
> 
> Bernie
> 
> My files in archive:
> WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API 
> 
> Can be downloaded here:
> <a
> href="http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan">http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan</a>

Only the parser will have this info when it processes calls to useit().
Some possibilities I can think of:
1/ define a list of identifiers user is supposed to type. Then useit() will look
its argument up in that table and substitute the right value if the name was
found. Emit a warning in that event as seen fit.
2/ Shroud user code and check the IL for a call to oseit() using a named symbol
rather than a manifest string constant. Tougher, of course. And if user codes
constant myString="WhatEver"
useit(myString)

this approach won't work.
It all depends on what level of safety you want/need. The more, the more
expensive.

CChris

new topic     » goto parent     » topic index » view message » categorize

11. Re: type checking ?

Bernie Ryan wrote:
> Derek Parnell wrote:
> > A user of Bernie's application must supply a couple of include files.
> > 
> > global constant WhatEver = "some text"
> 
>    Thanks for explaining it.
>    That is exactly what I mean.
>    How can you be sure that a user enters the token WhatEver which
>    represents a string constant and not the string "WhatEver"

Is the missing bit the way that constant is defined?
What if you did something similar to this:
global constant Whatever = fixedText("some text")

where fixedText just appended to allFixedText and returned the index, then useit
could be:
procedure useit(object txt)
   if atom(txt) then
      txt = allFixedText[txt]
   else
      if find(txt,allFixedText) then ?9/0 end if
   end if
end procedure

A smarter solution would be that useit always expects an integer idx param.

Regards,
Pete

new topic     » goto parent     » topic index » view message » categorize

12. Re: type checking ?

Pete Lomax wrote:
> 
> Bernie Ryan wrote:
> > Derek Parnell wrote:
> > > A user of Bernie's application must supply a couple of include files.
> > > 
> > > global constant WhatEver = "some text"
> > 
> >    Thanks for explaining it.
> >    That is exactly what I mean.
> >    How can you be sure that a user enters the token WhatEver which
> >    represents a string constant and not the string "WhatEver"
> 
> Is the missing bit the way that constant is defined?

I'm still a bit baffled about all of this.  I suppose that Bernie has
a sorta legitimate reason for doing all this, but it really strikes me
as the kind of thing that is the wrong solution.  There's probably a
better way.

The main question that keeps popping up for me is:

Why do you need to pass a parameter if you want to force them to 
pass a specific constant?

Matt

new topic     » goto parent     » topic index » view message » categorize

13. Re: type checking ?

Matt Lewis wrote:
> 

> Why do you need to pass a parameter if you want to force them to 
> pass a specific constant?
 
Matt:

<code>

---- File1
constant
strConstant1 = "This a string constant from file 1"
---- end of File1

---- File2
constant
strConstant2 = "This a string constant from file 2"
---- end of File2

---- File3
constant
strConstant3 = "This a string constant from file 3"
---- end of File3

---- MAIN FILE
include file1
include file2
include file3

procedure useit(sequence s)
  -- process s here
end procedure

-- These are ok
useit(strConstant1)
useit(strConstant2)
useit(strConstant3)

-- THIS IS WRONG BECAUSE OF THE QUOTES, I DO NOT WANT TO PROCESS THIS.

useit("strConstant1")

</code>

Bernie

My files in archive:
WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API 

Can be downloaded here:
http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan

new topic     » goto parent     » topic index » view message » categorize

14. Re: type checking ?

Here is how how I would do it...

<code>
---- File1
constant
strConstant1 = defineit("This a string constant from file 1")
---- end of File1

---- File2
constant
strConstant2 = defineit("This a string constant from file 2")
---- end of File2

---- File3
constant
strConstant3 = defineit("This a string constant from file 3")
---- end of File3

---- defstr.e ---
global type goodstr(object s)
    if atom(s) then return 0 end if
    is length(s) != 2 then return 0 end if
    if compare(s[1], {{"goodstr"}}) != 0 then return 0 end if
    if atom(s[2]) then return 0 end if
    for i = 1 to length(s[2]) do
        if not integer(s[2][i]) then return 0 end if
        if s[2][i] < 0 then return 0 end if
        if s[2][i] > 255 then return 0 end if
    end for
    return 1
end type

global function defineit(sequence s)
    return {{{"goodstr"}}, s}
end function
---- end of defstr.e


---- MAIN FILE
include defstr.e
include file1
include file2
include file3

procedure useit(goodstring s)
  -- process s here
  if goodstr(s) = 0 then return end if
end procedure

-- These are ok
useit(strConstant1)
useit(strConstant2)
useit(strConstant3)

-- THIS IS WRONG BECAUSE OF THE QUOTES, I DO NOT WANT TO PROCESS THIS.

useit("strConstant1")

</code>

-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

new topic     » goto parent     » topic index » view message » categorize

15. Re: type checking ?

Derek Parnell wrote:
> 
> Here is how how I would do it...

(SCNR)
Seems fine but sub-optimal to me, instead I would do this:

---- defstr.e ---
sequence defset
         defset={}

type flatstring(object o) -- if really needed
object ch
  if not sequence(o) then return 0 end if
  for i=1 to length(o) do
    ch=o[i]
    if not integer(o) or o<#00 or o>#FF then return 0 end if
--  (nb: use of "or" above may be suboptimal[?])
  end for
  return 1
end type

global function defineit(flatstring f)
   defset=append(defset,f)
   return length(defset)
end function

global function getstr(integer idx) -- or make defset global
  if idx<1 or idx> length(defset) then ?9/0 end if
  return defset[idx]
end function
---- end of defstr.e

---- File1
constant
strConstant1 = defineit("This a string constant from file 1")
---- end of File1

---- MAIN FILE
include defstr.e
include file1

procedure useit(integer idx)
sequence s
   s = getstr(idx) -- or just s=defset[idx]
   -- process s here
end procedure
 
-- This is ok
useit(strConstant1)

-- THIS IS WRONG BECAUSE OF THE QUOTES, I DO NOT WANT TO PROCESS THIS.

useit("strConstant1")
 


Simply put, making strConstant1 (etc) an INTEGER INDEX solves half the problem
right off the bat.

Regards,
Pete

new topic     » goto parent     » topic index » view message » categorize

16. Re: type checking ?

I wrote:
> }}}
<eucode>
> global function getstr(integer idx) -- or make defset global
>   if idx<1 or idx> length(defset) then ?9/0 end if
>   return defset[idx]
> end function
> procedure useit(integer idx)
> </eucode>
{{{


My OCD says: better typewise/error reporting is of course:
global type valididx(object idx)
   return integer(idx) and idx>= and idx<= length(defset)
end type
global function getstr(integer idx)
  return defset[idx]
end function
procedure useit(valididx idx)

 

Thataway any error should occur on the useit call itself, not two levels down in
the call stack...

Pete

new topic     » goto parent     » topic index » view message » categorize

17. Re: type checking ?

Bernie Ryan wrote:
> 
> Matt Lewis wrote:
> > 
> 
> > Why do you need to pass a parameter if you want to force them to 
> > pass a specific constant?
>  
> Matt:
> 
> <code>

<snipped>

> -- These are ok
> useit(strConstant1)
> useit(strConstant2)
> useit(strConstant3)
> 
> -- THIS IS WRONG BECAUSE OF THE QUOTES, I DO NOT WANT TO PROCESS THIS.
> 
> useit("strConstant1")
> 
> </code>

OK, once again, you've answered the what, but not the why.  I'll play 
dentist now and ask some more focused questions.

Where did file1, etc come from?  Are these user files?  Are they part
of your library?

Why is the distinction between a constant and a literal sequence important
to useit?

You say that you don't want to process a literal sequence.  Please explain 
the reason behind this.

Matt

new topic     » goto parent     » topic index » view message » categorize

18. Re: type checking ?

Matt Lewis wrote:
> 
> Bernie Ryan wrote:
> > 
> > Matt Lewis wrote:
> > > 
> > 
> > > Why do you need to pass a parameter if you want to force them to 
> > > pass a specific constant?
> >  
> > Matt:
> > 
> > <code>
> 
> <snipped>
> 
> > -- These are ok
> > useit(strConstant1)
> > useit(strConstant2)
> > useit(strConstant3)
> > 
> > -- THIS IS WRONG BECAUSE OF THE QUOTES, I DO NOT WANT TO PROCESS THIS.
> > 
> > useit("strConstant1")
> > 
> > </code>
> 
> OK, once again, you've answered the what, but not the why.  I'll play 
> dentist now and ask some more focused questions.
> 
> Where did file1, etc come from?  Are these user files?  Are they part
> of your library?

file1 is a resource file created by the user using a utility program. 
 
> Why is the distinction between a constant and a literal sequence important
> to useit?
>

useit() is a procedure in a library that is being used by the user.
 
> You say that you don't want to process a literal sequence.  Please explain 
> the reason behind this.
> 

I do not know in advance what constant name will generated by the user

generating the file.

So I was trying to type-check so the user entered the constant token name.

I think a figured away around it by having the utility embed a unique

indentifier in the generated sequence constant string.     


Bernie

My files in archive:
WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API 

Can be downloaded here:
http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu