#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    3
    Rep Power
    0

    Unhappy Help With A Problem!


    Hello to all!
    I'm really sorry to bother you all but I'm banging my head with this task from at least a week and I don't know how to solve this problem
    Basically I'm using HOPE language (I hope that anyone here is a bit familiar with this functional language!!) and my task is to define a function call precedens which takes two words and evaluates to true if the 1st word is alphabetically less than the second but both words have to be coverted in capital using a function called shout.
    I have to use 2 functions within the function precedens which I defined but I cannot link them all in one
    This is what I've done up to now...

    dec islower : char ->truval;
    --- islower x<= (x>='a') and (x=<'z');

    dec convforlower : char->char;
    --- convforlower x<= chr(ord(x)-32);

    dec convtoupper : char->char;
    --- convtoupper x<= if islower x = true
    then convforlower x
    else x;

    the functions above will check if a character is in lower case and if it is this char will be converted in upper case.
    The one below using the above functions will convert a list of char into uppercase and this is one of the 2 function that I have to use in precedens.

    dec shout : list char ->list char;
    --- shout nil<= nil;
    --- shout (h::tail)<= convtoupper h :: shout(tail);


    The one below is the 2nd function that I have to use in precedens
    that will get two list of char (2 words) and will check if the 1st word is alphabetically less then the 2nd.

    dec pre : list char # list char -> truval;
    --- pre (anylist, nil)<= false;
    --- pre (nil, h2::tail2)<=true;
    --- pre (h1::tail1, h2::tail2) <= if h1=h2
    then pre (tail1, tail2)
    else h1<h2;


    This is the one that doesn'e work!!
    This function will get 2 lists of char and check if the 1st one is alphabetically less then the 2nd. However before I can do this I have to connvert every char into uppercase... and this is my BIG PROBLEM!!!!

    dec precedens : list char # list char ->truval
    --- precedens (h1::tail1, h2::tail2)<= shout (h1:: tail1)
    shout (h2:: tail2)
    pre (h1::tail1, h2::tail2);

    I really hope that someone will give me a bit of help!!

    THANK YOU VRY MUCH IN ADVANCE!!!!
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    I'd be happy to help, unfortunatly i've never heard of HOPE.. a quick search on google also turned up nothing (except a few referances to Pascal). If you have a few links i could read up on it and maybe give you a hand, no promises

    Oh while i think about it you may get a better responce if you post this in the general forum, surly somone on devshed must know this lang'

    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    74
    Rep Power
    11
    Hi Mark,

    This is a link that I found for "Hope"
    http://www.soi.city.ac.uk/~ross/Hope/

    Random
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    3
    Rep Power
    0
    Originally posted by netytan
    I'd be happy to help, unfortunatly i've never heard of HOPE.. a quick search on google also turned up nothing (except a few referances to Pascal). If you have a few links i could read up on it and maybe give you a hand, no promises

    Oh while i think about it you may get a better responce if you post this in the general forum, surly somone on devshed must know this lang'

    Mark.
    Hi thanks a lot!
    I know there is not a lot on the net about this lang'
    I'm studing it I guess because of the strong use of functions...
    Anyway where do you think i could post this message?
    I had a look but there is just a list of different languages...
    I'll try to find something that can give you a bit more of help...
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    325
    Rep Power
    12

    Re: Help With A Problem!


    Try this.. you might need to edit it since I don't know the language. I've used other functional languages before tho.

    Notice the fact I spent time on thinking of a function name that explains the function almost entirely and so you don't need to read any comments or the code to understand what it does. Make this a habbit. The few seconds spent on it saves enourmous time later when u have to read large programs to understand what it all does and how it works.

    Code:
    dec isLower : char -> truval;
    --- isLower x<= (x>='a') and (x=<'z');
    
    dec upperChar : char -> char;
    --- upperChar x<= if isLower x = true
                      then chr(ord(x)-32);
                      else x;
    
    dec upperStr : list char -> list char;
    --- upperStr nil    <= nil;
    --- upperStr (h::t) <= upperChar h :: upperStr(t);                      
                
    dec compare : list char # list char -> truval;
    --- compare (anylist, nil)   <= false;
    --- compare (nil, anylist)   <= true; 
    --- compare (h1::t1, h2::t2) <= if h1=h2
                                    then compare (t1, t2);
                                    else h1 < h2;  
    
    dec precedens : list char # list char -> truval
    --- precedens (list1, list2)<= upperStr list1
                                   upperStr list2
                                   compare (list1, list2);

IMN logo majestic logo threadwatch logo seochat tools logo