string index and length

307 views
Skip to first unread message

Jaws

unread,
Nov 28, 2013, 6:52:28 PM11/28/13
to lci-g...@googlegroups.com
Hello:
I was wondering if there's a way to obtain characters in a string or the length of a string using lci. I am trying to count the number of "a","s", "d" and "f" in an input string (code below). I've managed to run my code in loljs (http://asgaard.co.uk/misc/loljs/), but lci seems to not recognize "LENGTH OF" or the "!" for index. I like having a local interpreter and the error messages in lci better.
Thanks!
Jaws

OBTW
This code was interpreted using loljs:
http://asgaard.co.uk/misc/loljs/#
TLDR
HAI 1.3
  CAN HAS STDIO?
  BTW read in the nucleotides from stdin
  I HAS A my_string
  GIMMEH my_string
  my_string IS NOW A YARN
  BTW initialize variables
  I HAS A a ITZ 0
  a IS NOW A NUMBR
  I HAS A s ITZ 0
  s IS NOW A NUMBR
  I HAS A d ITZ 0
  d IS NOW A NUMBR
  I HAS A f ITZ 0
  f IS NOW A NUMBR
  I HAS A i ITZ 0
  i IS NOW A NUMBR
  IM IN YR my_loop UPPIN YR i TIL BOTH SAEM i AN LEN OF my_string
    I HAS A char ITZ my_string!i
    char, WTF?
      OMG "A"
      OMG "a"
        a R SUM OF a AN 1
        GTFO
      OMG "S"
      OMG "s"
        s R SUM OF s AN 1
        GTFO
      OMG "D"
      OMG "d"
        d R SUM OF d AN 1
        GTFO
      OMG "F"
      OMG "f"
        f R SUM OF f AN 1
        GTFO
      OMGWTF
        GTFO
    OIC
  IM OUTTA YR my_loop
  VISIBLE SMOOSH a " " s " " d " " f MKAY
KTHXBYE

Justin Meza

unread,
Dec 1, 2013, 11:33:16 AM12/1/13
to lci-g...@googlegroups.com
Hi!  lci currently conforms to the 1.2 spec (http://wiki.lolcode.org/doku.php?id=1.2_spec) and some proposals from 1.3 (like BUKKITs), but neither of those have any string operations like length and index.

I don't think these would be too hard to implement in lci, but one way to fake this functionality of iterating through a string is to accept one character at a time as input (there's an example with an interpreter here: https://groups.google.com/forum/#!original/lci-devel/bwz6qqtfdIU/u5woK8KRVl8J).  So your input file would have each character on a separate line.

If you happen to implement these string operations, feel free to submit a pull request.

- Justin


--
You received this message because you are subscribed to the Google Groups "lci-general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lci-general...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Jaws

unread,
Dec 22, 2013, 2:04:27 PM12/22/13
to lci-g...@googlegroups.com
Hello:
Thanks for the reply. I think I'll stick to loljs for now since it's Turing complete. 
Jaws.

Justin Meza

unread,
Dec 23, 2013, 1:35:22 AM12/23/13
to lci-g...@googlegroups.com
No problem, sounds good.  Also, lci is Turing complete, too: the link I sent points to an interpreter for another language running on lci.  It just doesn't have some string operations yet.  :)

- Justin

Justin Meza

unread,
Jan 22, 2014, 11:15:18 PM1/22/14
to joce...@gmail.com, lci-g...@googlegroups.com
Hey Jaws,

I had a bit of time (in other words, I was procrastinating :P) and added some string standard library functions to the "future" branch of lci (at https://github.com/justinmeza/lci/tree/future) that might be useful to you (I'm working on adding a bunch of standard library functions to lci, including file I/O functions).  They can be accessed by adding "CAN HAS STRING?" to your code.  Based on your sample code, I added a function to get a character at a particular position in a string (STRING'Z STRATIN) and a string length function (STRING'Z STRLENIN).  So the code that I was able to run looks like:

OBTW
This code was interpreted using lci :)
TLDR
HAI 1.4
  CAN HAS STDIO?
  CAN HAS STRING?
  BTW read in the nucleotides from stdin
  I HAS A my_string
  GIMMEH my_string
  my_string IS NOW A YARN
  BTW initialize variables
  I HAS A a ITZ 0
  a IS NOW A NUMBR
  I HAS A s ITZ 0
  s IS NOW A NUMBR
  I HAS A d ITZ 0
  d IS NOW A NUMBR
  I HAS A f ITZ 0
  f IS NOW A NUMBR
  I HAS A i ITZ 0
  i IS NOW A NUMBR
  I HAS A strlen
  strlen R I IZ STRING'Z STRLENIN YR my_string MKAY
  IM IN YR my_loop UPPIN YR i TIL BOTH SAEM i AN strlen
    I HAS A char ITZ I IZ STRING'Z STRATIN YR my_string AN YR i MKAY
    char, WTF?
      OMG "A"
      OMG "a"
        a R SUM OF a AN 1
        GTFO
      OMG "S"
      OMG "s"
        s R SUM OF s AN 1
        GTFO
      OMG "D"
      OMG "d"
        d R SUM OF d AN 1
        GTFO
      OMG "F"
      OMG "f"
        f R SUM OF f AN 1
        GTFO
      OMGWTF
        GTFO
    OIC
  IM OUTTA YR my_loop
  VISIBLE SMOOSH a " " s " " d " " f MKAY
KTHXBYE

Sorry it's so late, but I thought you might still be interested.  I will probably be adding more standard library functions in the near future, but if you need others, just let me know and I can try and add them sooner.

- Justin

Jaws

unread,
Feb 3, 2014, 2:19:02 AM2/3/14
to lci-g...@googlegroups.com
Awesome. Thanks for procrastinating and spending that time working on a good lolcode interpreter. This is much appreciated. I haven't had much time to spend on lolcode lately either but I will check it out soon :) Thanks again!

Mike Burr

unread,
Oct 16, 2014, 6:45:11 PM10/16/14
to lci-g...@googlegroups.com
Hi,

Quick question, I just did a clone of the latest lci from April 21:

commit a315f2bac326f5c3b6a2d740d98041ede3c94f44
Author: Justin Meza <XXXXXXXXXXX>
Date:   Mon Apr 21 00:51:10 2014 -0400

    updated webpage

I'm having trouble running the code sample in your post above. I built lci on Fedora 20 with:

 ./install.py -t -p /home/burrm/bin/lci

Running the code sample gives:

lctest.lci:3: unknown token at: STRING?

Thoughts?

Thanks,

Mike

Justin Meza

unread,
Oct 16, 2014, 6:52:49 PM10/16/14
to lci-g...@googlegroups.com
Hi Mike,

Try running it using the latest commit on the "future" branch:  https://github.com/justinmeza/lci/commit/e8dd671a2719e2a62f7cbed111ffe2006f436e7e .  We're keeping all experimental features here until we can come up with a new specification that includes them.

For a longer example, check out the HTTP server I wrote that does some string parsing with this library:  https://github.com/justinmeza/httpd.lol/blob/master/httpd.lol .

- Justin

--
You received this message because you are subscribed to the Google Groups "lci-general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lci-general...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages