How can I convert uppercase input to the lowercase?

selubamih

I have a predicate that takes two arguments in which the first argument can be a compound one and the second argument is always B. I have also defined some new operators like + and &.

pvc(A, B) :- somestuff(A, B).

Here the user may type something like pvc((x+y)&(A+b), B).
As a beginner in Prolog, what I want to do is to convert the compound A to all lowercase and call somestuff with new AN. So it shall be somestuff((x+y)&(a+b), B).

I tried something like pvc(A, B) :- downcase_atom(A,AN),somestuff(AN, B).
But it doesn't seem like to be the correct way. I will appreciate any help.

Daniel Lyons

So, you will need to induct on the structure of your thing, and the easiest way to do this is with the univ operator =../2. First handle your base case, which you did:

downcase_compound(A, B) :- atom(A), downcase_atom(A, B).

Now you will take the structure apart and induct on it using univ:

downcase_compound(A, B) :-
   compound(A),
   A =.. [Functor|Args],
   downcase_compound(Functor, DowncaseFunctor),
   maplist(downcase_compound, Args, DowncaseArgs),
   B =.. [DowncaseFunctor|DowncaseArgs].

The trick here is simply breaking your compound down into bits you can use, and then recursively calling downcase_compound/2 on those bits. See it in action:

?- downcase_compound((x+y,('A'+b)), X).
X =  (x+y, a+b) 

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I convert uppercase letters to lowercase in Notepad++

How can i convert uppercase in lowercase inside a list?

How can I convert from uppercase to lowercase all directories and sub-directories in Ubuntu 16.04.2?

How to convert uppercase letter to lowercase?

How do I convert strings between uppercase and lowercase in Java?

How can I test if a letter in a string is uppercase or lowercase using JavaScript?

Scala how can I uppercase first character and lowercase others

How can i check if the file extension is uppercase or lowercase?

How do I make an list that can be read as either uppercase or lowercase

Can't convert lowercase to uppercase with pointer

How can I use regex to convert Uppercase text to lowercase text in combination with a look-ahead and look-behind

How can I convert my strings to lowercase?

How can I convert Unicode to uppercase to print it?

How to NOT convert uppercase to lowercase after using regex?

How to convert a selection to lowercase or uppercase in Sublime Text

Convert first lowercase to uppercase and uppercase to lowercase (regex?)

I Can't Convert These to Uppercase

I want to convert uppercase words to lowercase in dataframe and put them below

How can I indent a string when lowercase meets uppercase, like in thisSentence?

What's making the texts lowercase in this Corpora, and how can I turn it uppercase?

How can I build a password with 2 random lowercase, uppercase, numbers and punctuation?

How can I code the program to accept not only uppercase but also lowercase first letter?

How can I convert all forms of a specific word in a String to lowercase?

how to make this lowercase and uppercase

How to read uppercase as lowercase?

How can I convert an Exchange property to uppercase in 'simple'?

How can I convert the first character of a column to an uppercase for every row?

How can I convert a single Character type to uppercase?

How can I convert to uppercase stderr output but not stdout?