Erlang/OTP Forums

Author Message

<  Erlang  ~  comparing substrings

badlucky
Posted: Wed Jan 06, 2010 2:17 am Reply with quote
Joined: 05 Jan 2010 Posts: 1
so im new to erlang and here is what i have so far...
-module(abc).
-export([main/0,findMatch/1]).

main()->
findMatch("abcabcabc").


findMatch(word)->
sub_string(word,1,3)->p1;
sub_string(word,4,6)->p2;
sub_string(word,7,9)->p3;
if p1 == p2 == p3 -> true.


im trying to take 9 letters as one string and break it up into three parts seeing if all three are identical, if so then true, else its false

how can i compare the substrings/ what am i missing to get this to at least compile??
View user's profile Send private message
Allan
Posted: Wed Jan 06, 2010 12:57 pm Reply with quote
User Joined: 29 Jun 2009 Posts: 30
badlucky wrote:
what am i missing to get this to at least compile??

You have to define sub_string/3 somewhere and/or prefix the calls with the name of the module containing the function declaration.
Multiple expressions have to be separated by comma in a function body.
Expression results are assigned to variables by first writing the variable's name, followed by an equal sign and the expression.
Variable names begin always with an uppercase letter.

Try something like this:
Code:
-module(abc).
-export([main/0, findMatch/1]).
 
main()-> findMatch("abcabcabc").

findMatch(Word)->
  P1 = string:substr(Word, 1, 3),
  P2 = string:substr(Word, 4, 3),
  P3 = string:substr(Word, 7, 3),
  (P1 =:= P2) andalso (P2 =:= P3)
.

Other people interested in Erlang Syntax were interested in Sequential Programming in the Erlang documentation too.
View user's profile Send private message Send e-mail ICQ Number
Sergio Salvato
Posted: Thu Jan 07, 2010 4:32 pm Reply with quote
Joined: 07 Sep 2009 Posts: 2
Or something like this:
Code:

-module(abc).
-export([main/0, findMatch/1]).
 
main()-> findMatch("abcabcabc").

findMatch([A, B, C, A, B, C, A, B, C])-> true;
findMatch(_) -> false.
View user's profile Send private message
wuji
Posted: Fri Sep 14, 2012 6:50 am Reply with quote
User Joined: 10 Aug 2012 Posts: 654
seems possible for Colon who, according to police, joined three other accomplices accomplices [h2]cheap replica *beep*[/h2] accomplices to rob, and ultimately kill, Marcelo Vera in a botched stickup.Miami-Dade
said the "investigation is still ongoing" but confirmed facts of the crime crime [h4]replica designer *beep*[/h4] crime detailed in Colon's arrest warrant and obtained by the Miami Herald.According
the Herald, Colon met a friend, Stephany Concepcion, 26, and two two jordan 11 two other men identified only as "Big Killer" and "Crazy Dread" before
to rob Vero, an artist known to keep large amounts of cash cash cheap jordan shoes cash in his home.Conception, Vero's former employee, arrived at his house late
the night of Jan. 6, 2006. From the victim's bathroom, she called called jordan concord called Colon and told him the time was right for the robbery,
to the warrant.Conception said she heard shots fired from the other room. room. jordan 11 concords room. When she ran outside, the other men had driven off and
was alone at the scene when police arrived. She was arrested and and cheap designer *beep* and pleaded guilty to second-degree murder. She was sentenced to 15 years
View user's profile Send private message
dongdongwu
Posted: Wed Sep 19, 2012 7:49 am Reply with quote
User Joined: 19 Sep 2012 Posts: 236
Girls would refuse to even leave their replicas behind. specifically when the product beats the complete meaning of the Christian Louboutin men outlet; in conditions of good quality and detailing.If Cinderella was residing in your twenty primary century as opposed to the aged a single then there would not be any 'Happy actually after'. properly appears like girls nowadays are as well fond of the strong;Christian Louboutin Men Shoes to leave them in your center of nowhere.Christian Louboutin for men Shoes would arrive true handy being a excellent handbag using the glimpse and really feel belonging to the authentic but at a very much lesser price tag adding as very much as types picture in your process.
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum