List of strings problem

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

List of strings problem

Sam Overdorf
I have a list of strings I am trying to process with the "|".
D = [ "sam1", "sam2" ]

[H|T] = D gives me H = "sam1"
[H2|T2] = T gives me "s" I was wanting the string "sam2" not the "s".

What am I doing wrong?

Thanks,
Sam Overdorf
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: List of strings problem

Vlad Dumitrescu-2
Hi, 
It works as expected for me. Are you sure that D elements are separated by comma and not by | ? 
Regards, 
Vlad 


On 20 Jul 2017 08:43, "Sam Overdorf" <[hidden email]> wrote:
I have a list of strings I am trying to process with the "|".
D = [ "sam1", "sam2" ]

[H|T] = D gives me H = "sam1"
[H2|T2] = T gives me "s" I was wanting the string "sam2" not the "s".

What am I doing wrong?

Thanks,
Sam Overdorf
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: List of strings problem

PAILLEAU Eric
In reply to this post by Sam Overdorf
Hi,
T is already sam2.
Strings are list so try [H2|T2]=[T] ... 
Regards 

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: List of strings problem

Taras Halturin
Just to be sure...

Erlang/OTP 19 [erts-8.2.1] [source] [64-bit] [smp:4:4] [async-threads:10] [kernel-poll:false]

Eshell V8.2.1  (abort with ^G)
1> D = [ "sam1", "sam2" ].
["sam1","sam2"]
2> [H|T] = D.
["sam1","sam2"]
3> [H2|T2] = T.
["sam2"]
4> T2.
[]
5> H2.
"sam2"
6> 

It works as you expected. 

On Thu, Jul 20, 2017 at 10:00 AM, Éric Pailleau <[hidden email]> wrote:
Hi,
T is already sam2.
Strings are list so try [H2|T2]=[T] ... 
Regards 

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions




--
Best Regards.
Taras Halturin

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: List of strings problem

PAILLEAU Eric
Yes,
indeed it is the normal behaviour.
I suspect you do something like list flatten before so that
[H2|T2] = T.
is
[H2|T2] = [$s,$a,$m,$2]   and you got "s".
the reason why I told you to do
[H2|T2] = [T].

but minimal test is correct like Taras pointed.

regards

Le 20/07/2017 à 09:31, Taras Halturin a écrit :

> Just to be sure...
>
> Erlang/OTP 19 [erts-8.2.1] [source] [64-bit] [smp:4:4]
> [async-threads:10] [kernel-poll:false]
>
> Eshell V8.2.1  (abort with ^G)
> 1> D = [ "sam1", "sam2" ].
> ["sam1","sam2"]
> 2> [H|T] = D.
> ["sam1","sam2"]
> 3> [H2|T2] = T.
> ["sam2"]
> 4> T2.
> []
> 5> H2.
> "sam2"
> 6>
>
> It works as you expected.
>
> On Thu, Jul 20, 2017 at 10:00 AM, Éric Pailleau
> <[hidden email] <mailto:[hidden email]>> wrote:
>
>     Hi,
>     T is already sam2.
>     Strings are list so try [H2|T2]=[T] ...
>     Regards
>
>     _______________________________________________
>     erlang-questions mailing list
>     [hidden email] <mailto:[hidden email]>
>     http://erlang.org/mailman/listinfo/erlang-questions
>     <http://erlang.org/mailman/listinfo/erlang-questions>
>
>
>
>
> --
> Best Regards.
> Taras Halturin

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: List of strings problem

Sam Overdorf
Thanks for responding so quickly.
I am using Windows7 could this be causing some of my odd behavior?
Thanks,
Sam


On Thu, Jul 20, 2017 at 12:38 AM, PAILLEAU Eric
<[hidden email]> wrote:

> Yes,
> indeed it is the normal behaviour.
> I suspect you do something like list flatten before so that
> [H2|T2] = T.
> is
> [H2|T2] = [$s,$a,$m,$2]   and you got "s".
> the reason why I told you to do
> [H2|T2] = [T].
>
> but minimal test is correct like Taras pointed.
>
> regards
>
> Le 20/07/2017 à 09:31, Taras Halturin a écrit :
>>
>> Just to be sure...
>>
>> Erlang/OTP 19 [erts-8.2.1] [source] [64-bit] [smp:4:4] [async-threads:10]
>> [kernel-poll:false]
>>
>> Eshell V8.2.1  (abort with ^G)
>> 1> D = [ "sam1", "sam2" ].
>> ["sam1","sam2"]
>> 2> [H|T] = D.
>> ["sam1","sam2"]
>> 3> [H2|T2] = T.
>> ["sam2"]
>> 4> T2.
>> []
>> 5> H2.
>> "sam2"
>> 6>
>>
>> It works as you expected.
>>
>> On Thu, Jul 20, 2017 at 10:00 AM, Éric Pailleau <[hidden email]
>> <mailto:[hidden email]>> wrote:
>>
>>     Hi,
>>     T is already sam2.
>>     Strings are list so try [H2|T2]=[T] ...
>>     Regards
>>
>>     _______________________________________________
>>     erlang-questions mailing list
>>     [hidden email] <mailto:[hidden email]>
>>     http://erlang.org/mailman/listinfo/erlang-questions
>>     <http://erlang.org/mailman/listinfo/erlang-questions>
>>
>>
>>
>>
>> --
>> Best Regards.
>> Taras Halturin
>
>
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: List of strings problem

Raimo Niskanen-2
On Thu, Jul 20, 2017 at 04:57:34PM -0700, Sam Overdorf wrote:
> Thanks for responding so quickly.
> I am using Windows7 could this be causing some of my odd behavior?
> Thanks,
> Sam

Nope.  That should not matter.

Please re-do your example and cut-and-paste the result hera again, exactly
as Taras did, so there is no room for human error or interpretation...

    f().
    D = [ "sam1", "sam2" ].
    [H|T] = D.
    H.
    [H2|T2] = T.
    H2.



>
>
> On Thu, Jul 20, 2017 at 12:38 AM, PAILLEAU Eric
> <[hidden email]> wrote:
> > Yes,
> > indeed it is the normal behaviour.
> > I suspect you do something like list flatten before so that
> > [H2|T2] = T.
> > is
> > [H2|T2] = [$s,$a,$m,$2]   and you got "s".
> > the reason why I told you to do
> > [H2|T2] = [T].
> >
> > but minimal test is correct like Taras pointed.
> >
> > regards
> >
> > Le 20/07/2017 à 09:31, Taras Halturin a écrit :
> >>
> >> Just to be sure...
> >>
> >> Erlang/OTP 19 [erts-8.2.1] [source] [64-bit] [smp:4:4] [async-threads:10]
> >> [kernel-poll:false]
> >>
> >> Eshell V8.2.1  (abort with ^G)
> >> 1> D = [ "sam1", "sam2" ].
> >> ["sam1","sam2"]
> >> 2> [H|T] = D.
> >> ["sam1","sam2"]
> >> 3> [H2|T2] = T.
> >> ["sam2"]
> >> 4> T2.
> >> []
> >> 5> H2.
> >> "sam2"
> >> 6>
> >>
> >> It works as you expected.
> >>
> >> On Thu, Jul 20, 2017 at 10:00 AM, Éric Pailleau <[hidden email]
> >> <mailto:[hidden email]>> wrote:
> >>
> >>     Hi,
> >>     T is already sam2.
> >>     Strings are list so try [H2|T2]=[T] ...
> >>     Regards
> >>
> >>     _______________________________________________
> >>     erlang-questions mailing list
> >>     [hidden email] <mailto:[hidden email]>
> >>     http://erlang.org/mailman/listinfo/erlang-questions
> >>     <http://erlang.org/mailman/listinfo/erlang-questions>
> >>
> >>
> >>
> >>
> >> --
> >> Best Regards.
> >> Taras Halturin
> >
> >
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions

--

/ Raimo Niskanen, Erlang/OTP, Ericsson AB
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: List of strings problem

Sam Overdorf
Thanks for the help.
I figured out my problem, I was going to deep into the list.
Works as expected.
Thanks,
Sam


On Thu, Jul 20, 2017 at 11:40 PM, Raimo Niskanen
<[hidden email]> wrote:

> On Thu, Jul 20, 2017 at 04:57:34PM -0700, Sam Overdorf wrote:
>> Thanks for responding so quickly.
>> I am using Windows7 could this be causing some of my odd behavior?
>> Thanks,
>> Sam
>
> Nope.  That should not matter.
>
> Please re-do your example and cut-and-paste the result hera again, exactly
> as Taras did, so there is no room for human error or interpretation...
>
>     f().
>     D = [ "sam1", "sam2" ].
>     [H|T] = D.
>     H.
>     [H2|T2] = T.
>     H2.
>
>
>
>>
>>
>> On Thu, Jul 20, 2017 at 12:38 AM, PAILLEAU Eric
>> <[hidden email]> wrote:
>> > Yes,
>> > indeed it is the normal behaviour.
>> > I suspect you do something like list flatten before so that
>> > [H2|T2] = T.
>> > is
>> > [H2|T2] = [$s,$a,$m,$2]   and you got "s".
>> > the reason why I told you to do
>> > [H2|T2] = [T].
>> >
>> > but minimal test is correct like Taras pointed.
>> >
>> > regards
>> >
>> > Le 20/07/2017 à 09:31, Taras Halturin a écrit :
>> >>
>> >> Just to be sure...
>> >>
>> >> Erlang/OTP 19 [erts-8.2.1] [source] [64-bit] [smp:4:4] [async-threads:10]
>> >> [kernel-poll:false]
>> >>
>> >> Eshell V8.2.1  (abort with ^G)
>> >> 1> D = [ "sam1", "sam2" ].
>> >> ["sam1","sam2"]
>> >> 2> [H|T] = D.
>> >> ["sam1","sam2"]
>> >> 3> [H2|T2] = T.
>> >> ["sam2"]
>> >> 4> T2.
>> >> []
>> >> 5> H2.
>> >> "sam2"
>> >> 6>
>> >>
>> >> It works as you expected.
>> >>
>> >> On Thu, Jul 20, 2017 at 10:00 AM, Éric Pailleau <[hidden email]
>> >> <mailto:[hidden email]>> wrote:
>> >>
>> >>     Hi,
>> >>     T is already sam2.
>> >>     Strings are list so try [H2|T2]=[T] ...
>> >>     Regards
>> >>
>> >>     _______________________________________________
>> >>     erlang-questions mailing list
>> >>     [hidden email] <mailto:[hidden email]>
>> >>     http://erlang.org/mailman/listinfo/erlang-questions
>> >>     <http://erlang.org/mailman/listinfo/erlang-questions>
>> >>
>> >>
>> >>
>> >>
>> >> --
>> >> Best Regards.
>> >> Taras Halturin
>> >
>> >
>> _______________________________________________
>> erlang-questions mailing list
>> [hidden email]
>> http://erlang.org/mailman/listinfo/erlang-questions
>
> --
>
> / Raimo Niskanen, Erlang/OTP, Ericsson AB
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions