Thread: Why should I learn Lisp?

  1. #31
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by Alpo View Post
    @MutantJohn - Why PHP though? What does it have some advantage over other languages? Like for instance if I knew C++, HTML, JavaScript, and CSS, would there still be a need for PHP?
    It's a bit difficult to implement server-side scripting in C++, for the lack of a proper framework. But he did have other more interesting options. When Laserlight first suggested Python, I wholeheartedly agreed. Not only he gets server-side scripting, but he gets to learn a programming language that is ubiquitous across a large range of other applications. Being a general purpose language, he can use it to code GUI and CLI applications, code stored procedures inside databases and extend applications with scripting.

    Quote Originally Posted by Alpo View Post
    Aren't you a moderator though? Oh lord, laserlight's compromised too, everyone run!
    Our accounts are all ran by our little brothers.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  2. #32
    Ticked and off
    Join Date
    Oct 2011
    Location
    La-la land
    Posts
    1,728
    Quote Originally Posted by Jimmy View Post
    Nominal Animal, are you sick or are you drunk at the moment?
    Neither, I just like type-punning too.

    Quote Originally Posted by Jimmy View Post
    I mean, since when do you answer with only 1 sentence?!?
    I don't know. It was a freestanding statement and not an answer.

    Let me try to scare you a bit more. Here's a poem that popped into my head while cringing from a stupid XMLHttpRequest error I made in another thread:

    A snowflake lands on a shiny new pebble
    Come spring, only the pebble remains
    anxiously awaiting adventure
    Between your sock and your shoe

  3. #33
    Lurker
    Join Date
    Dec 2004
    Posts
    296
    Quote Originally Posted by Nominal Animal View Post
    Neither, I just like type-punning too.


    I don't know. It was a freestanding statement and not an answer.

    Let me try to scare you a bit more. Here's a poem that popped into my head while cringing from a stupid XMLHttpRequest error I made in another thread:

    A snowflake lands on a shiny new pebble
    Come spring, only the pebble remains
    anxiously awaiting adventure
    Between your sock and your shoe
    That's more like it. It was probably only low blood sugar I guess. It looks like he's slowly getting back to normal again.

  4. #34
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Quote Originally Posted by Nominal Animal View Post
    Let me try to scare you a bit more. Here's a poem that popped into my head while cringing from a stupid XMLHttpRequest error I made in another thread:

    A snowflake lands on a shiny new pebble
    Come spring, only the pebble remains
    anxiously awaiting adventure
    Between your sock and your shoe
    Very poetic. Wow. True talent.



    (Any similarity to Doge is not intended and is entirely coincidental.)

  5. #35
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Quote Originally Posted by Mario F. View Post
    It's a bit difficult to implement server-side scripting in C++, for the lack of a proper framework. But he did have other more interesting options. When Laserlight first suggested Python, I wholeheartedly agreed. Not only he gets server-side scripting, but he gets to learn a programming language that is ubiquitous across a large range of other applications. Being a general purpose language, he can use it to code GUI and CLI applications, code stored procedures inside databases and extend applications with scripting.
    Pretty much this.

    Doing everything I did in PHP in C++ would've been a nightmare. PHP is nice because it just works. I've made it a point to read the documentation of each function I use. A lot of the PHP user comments have helped a ton too. As well as Nominal's and phantom's code samples in my other thread.

    Python and I have mixed feelings. Do I hate it because it forces scope through indentation? Yes. Do I hate it because my solid state professor made us use it for the course and we mutually despise each other? Yes.

    I don't think Python is a bad language but I'm very apprehensive of it. I'm just a little kitty dipping his paws in the water and is very unsure of diving in.

  6. #36
    Lurker
    Join Date
    Dec 2004
    Posts
    296
    Quote Originally Posted by MutantJohn View Post
    Pretty much this.

    Doing everything I did in PHP in C++ would've been a nightmare. PHP is nice because it just works. I've made it a point to read the documentation of each function I use. A lot of the PHP user comments have helped a ton too. As well as Nominal's and phantom's code samples in my other thread.

    Python and I have mixed feelings. Do I hate it because it forces scope through indentation? Yes. Do I hate it because my solid state professor made us use it for the course and we mutually despise each other? Yes.

    I don't think Python is a bad language but I'm very apprehensive of it. I'm just a little kitty dipping his paws in the water and is very unsure of diving in.
    Maybe try Ruby?

    I'm not saying that Ruby is better than Python, I would even argue that Python is still a more mature and efficient language than Ruby, but Ruby is fun to use. It can be good with another perspective, and who knows, using Ruby might make you appreciate Python more in the end.

    For the record, I use both Python and Ruby and I like them both.

  7. #37
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Quote Originally Posted by MutantJohn View Post
    Do I hate it [PHP] because it forces scope through indentation? Yes.
    Why do you not also hate C++ for forcing scope through curly braces?

  8. #38
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Quote Originally Posted by Yarin View Post
    Why do you not also hate C++ for forcing scope through curly braces?
    Curly braces always made more sense to me for some reason. It seems more akin to how we did things in our physics classes. I was used to using braces to help define scope for functions and stuff. Like for big equations, we'd have to wind up using
    Code:
    { stuff * [ derivatives of stuff * ( equations here) ] - other junk }
    so braces just make sense to me.

    Python is a great noobie language because the language itself literally forces you to have a consistent indentation style. I'm not a big fan of that. I prefer being anally retentive when I want/like to be.

  9. #39
    Ticked and off
    Join Date
    Oct 2011
    Location
    La-la land
    Posts
    1,728
    You know, if you want to write C or C++ CGI binaries, there is qDecoder. I played with it when it was still in its infancy, around the turn of the century. Since then, qDecoder has even grown FastCGI support.

    The most infuriating thing then was the numerous browser bugs and incompatibilities, especially with file uploads and trying to get the browser to use a specific character set (UTF-8), or even to tell what character set, it happened to use for the uploaded text boxes. I tried to compile a comprehensive list of browser-specific fixes, until I realized that a robust, error-tolerant approach was better than trying to cater for individual browsers.

  10. #40
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    Quote Originally Posted by Yarin View Post
    Forth is the engineer's equivalent.
    Since reading this, I went and checked out Forth and want to use it more and more every time I look at it. I've got an HP calculator that uses the RPN notation (which I love), so at least having a Forth prompt on my computer seems appealing.

  11. #41
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by MutantJohn View Post
    Python is a great noobie language because the language itself literally forces you to have a consistent indentation style. I'm not a big fan of that. I prefer being anally retentive when I want/like to be.
    Consistent indentation is a necessity in any programming language. It's also somewhat hard to avoid. After all, you aren't going to change your tab spaces configuration mid file.

    Python is surprisingly permissive in what it lets you do with whitespaces. The expressions below will result in the same working code.

    Code:
    print(int    ('4') + 4)
    print(int('4') + 4)
    Consistent indentation is only imposed on the lines after the first. That is, it needs to remain consistent only on lines that are related to the current nested block/ The following two 'if' constructs are valid code:

    Code:
    if True:
                   print(True)
                   print(int(True))
    else:
        print(False)
        print(int(False))
    
    
    if True:
                          print(True)
                          print(int(True))
    else:
                          print(False)
                          print(int(False))
    Line continuation characters, like parenthesis, allow complete indentation freedom. The following is valid python code:

    Code:
    print(
                4
                    +
          1
                  )
    And since you can wrap almost anything in parenthesis, you can create all forms of indentation. The following is also valid python code, and very similar to what you would see on a C code snippet:

    Code:
    if True: (
        print(True)
    )
    else: (
        print(False)
    )
    Incidentally, it's not only parenthesis that can work as line continuations characters. Curly braces and square brackets do too. But these have attached semantics and depending of how they are applied, can have undesired side-effects.

    Code:
    if True: {
        print(True)
    }
    else: {
        print(False)
    }
    
    # The above outputs:
    # True
    # {None}
    
    
    if True: [
        print(True)
    ]
    else: [
        print(False)
    ]
    
    # The above outputs:
    # True
    # [None]
    And there's also the semicolon, which removes most needs for indentation by grouping discreet compound statements into a single line. The following is working code:

    Code:
    if True: print(True); print(int(True))
    else: print(False); print(int(False))
    I hope I have shown to you that Python is in fact a whole lot more permissive than say delimiter-based languages. Its one and only indentation rule is actually pretty simple and an universal best practice among all programming languages.

    The only thing that may trip some coders is instead the absence of imposed delimiters. But my experience has shown me that it is only a matter of a short time until one just gets used to it and Python code ends up reading as easily, if not more easily, than C or C++.

    EDIT:
    Technically it is not true that Python doesn't impose a block delimiter. That delimiter exists and it is obligatory. It's the colon you see in the code snippets above. It's just not a paired-delimiter as we usually see in other languages.
    Last edited by Mario F.; 02-03-2015 at 05:21 PM.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  12. #42
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    Technically it is not true that Python doesn't impose a block delimiter. That delimiter exists and it is obligatory. It's the colon you see in the code snippets above.
    O_o

    If you actually want to get technical, the `:' token isn't the "open block-delimiter" for the Python language.

    Let's take a brief look at part of the grammar for a parser for a language not unlike C for the sake of context:

    Code:
    add_expr: term ('+' term)*
    // ...
    opr_expr: add_expr | sub_expr // many more
    // ...
    spl_stmt: (opr_expr | fcl_expr) ';'
    // ...
    grp_stmt: '{'  (spl_stmt)* '}'
    // ...
    bnch_if: "if" '(' cnd_stmt ')' grp_stmt | spl_stmt
    The group statement can't exist without the "open block-delimiter" and "close block-delimiter".

    Let's take a brief look at part of the grammar for the Python language:

    Code:
    add_expr: term ('+' term)*
    // ...
    opr_expr: add_expr | sub_expr // many more
    // ...
    smll_stmt: opr_expr | prnt_stmt // many more
    // ...
    grp_stmt: NL INDT smll_stmt+ DINT
    // ...
    bnch_if: 'if' cnd_stmt ':' grp_stmt | smll_stmt
    The branch itself can't exist without the ':' character.

    Now let's look at some similar code for both languages:

    Code:
    if True:
        print("Hello, World!")
    Code:
    if(true)
    {
        printf("Hello, World!");
    }
    Code:
    The ':' character is more related to the ')' than the '{' character.
    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  13. #43
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by phantomotap View Post
    O_o
    If you actually want to get technical, the `:' token isn't the "open block-delimiter" for the Python language.
    Well alright But your explanation didn't convince me either.

    To get technically technical, let's look instead at suite, where blocks are actually defined:

    Code:
    compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated
    if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]
    while_stmt: 'while' test ':' suite ['else' ':' suite]
    for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]
    try_stmt: ('try' ':' suite
               ((except_clause ':' suite)+
                ['else' ':' suite]
                ['finally' ':' suite] |
               'finally' ':' suite))
    with_stmt: 'with' with_item (',' with_item)*  ':' suite
    with_item: test ['as' expr]
    except_clause: 'except' [test [('as' | ',') test]]
    suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT
    Along with funcdef and classdef, all suite is preceded by the : delimiter. So : is really more like '{'. And not '('
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  14. #44
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    [Edit]
    TL;DR: You may consider what constitutes the block statement associated with branching, class definitions, and similar by considering what characters semantically and grammatically bind to what tokens. The `simple_stmt' and `stmt' do not have a rule for a leading ':' character so any sentence beginning with a ':' is invalid. The actual block statement, the alternative to a single `simple_stmt' within the `suite' rule, begins with the `NEWLINE' and `INDENT' rule leaving the ':' character to bind with the other related statements.
    [/Edit]

    To get technically technical, let's look instead at suite, where blocks are actually defined:
    O_o

    You've confused yourself by looking at the official grammar because they didn't separate, as I did on your behalf, the statement rule versus block rule.

    I'll show you again by making the same split with the copy of the official grammar you posted.

    Code:
    compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated
    if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]
    while_stmt: 'while' test ':' suite ['else' ':' suite]
    for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]
    try_stmt: ('try' ':' suite
               ((except_clause ':' suite)+
                ['else' ':' suite]
                ['finally' ':' suite] |
               'finally' ':' suite))
    with_stmt: 'with' with_item (',' with_item)*  ':' suite
    with_item: test ['as' expr]
    except_clause: 'except' [test [('as' | ',') test]]
    BLOCK: NEWLINE INDENT stmt+ DEDENT
    suite: simple_stmt | BLOCK
    The `suite' rule doesn't just represent a block. The `suite' rule represents a statement or a block.

    The "or" is the source or your confusion.

    Remove the "or" to yeild "suite: BLOCK" and consider the following:

    Code:
    # The example is invalid.
    if True: print("Hello, World!")
    # if(true) printf("Hello, World!");
    Code:
    # The example is valid.
    if True:
        print("Hello, World!")
    # if(true){printf("Hello, World!");}
    Remove the "or" to yeild "suite: simple_stmt" and consider the following:

    Code:
    # The example is valid.
    if True: print("Hello, World!")
    # if(true) printf("Hello, World!");
    Code:
    # The example is invalid.
    if True:
        print("Hello, World!")
    # if(true){printf("Hello, World!");}
    Once again, the ':' character binds as part of the relevant statement not the block.

    If the ':' character did bind as you suggest to the block, you could change the grammar:

    Code:
    compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated
    if_stmt: 'if' test suite ('elif' test suite)* ['else' suite]
    while_stmt: 'while' test suite ['else' suite]
    for_stmt: 'for' exprlist 'in' testlist suite ['else' suite]
    try_stmt: ('try' suite
               ((except_clause suite)+
                ['else' suite]
                ['finally' suite] |
               'finally' suite))
    with_stmt: 'with' with_item (',' with_item)*  suite
    with_item: test ['as' expr]
    except_clause: 'except' [test [('as' | ',') test]]
    suite: simple_stmt | ':' NEWLINE INDENT stmt+ DEDENT
    Actually, let's go ahead and do the same split for convenience:

    Code:
    compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated
    if_stmt: 'if' test suite ('elif' test suite)* ['else' suite]
    while_stmt: 'while' test suite ['else' suite]
    for_stmt: 'for' exprlist 'in' testlist suite ['else' suite]
    try_stmt: ('try' suite
               ((except_clause suite)+
                ['else' suite]
                ['finally' suite] |
               'finally' suite))
    with_stmt: 'with' with_item (',' with_item)*  suite
    with_item: test ['as' expr]
    except_clause: 'except' [test [('as' | ',') test]]
    BLOCK: ':' NEWLINE INDENT stmt+ DEDENT
    suite: simple_stmt | BLOCK
    Remove the "or" from the augmented grammar to yeild "suite: BLOCK" and consider the following:

    Code:
    # The example is invalid.
    if True print("Hello, World!")
    # if(true) printf("Hello, World!");
    Code:
    # The example is valid.
    if True:
        print("Hello, World!")
    # if(true){printf("Hello, World!");}
    Remove the "or" from the augmented grammar to yeild "suite: simple_stmt" and consider the following:

    Code:
    # The example is valid.
    if True print("Hello, World!")
    # if(true) printf("Hello, World!");
    Code:
    # The example is invalid.
    if True:
        print("Hello, World!")
    # if(true){printf("Hello, World!");}
    You may not be able to see it with the examples I've shown, but we have introduced a semantic ambiguity.

    Let's consider a non-literal condition with the augmented grammar to illustrate an instance of the ambiguity:

    Code:
    if var1 - DoSomething() + var2 and print("Hello, World!")
    These example are both valid code from among the possible interpretations:

    Code:
    if var1: -DoSomething() + var2 and print("Hello, World!")
    Code:
    if var1 - DoSomething(): +var2 and print("Hello, World!")
    Along with funcdef and classdef, all suite is preceded by the : delimiter.
    Try looking at the examples in terms of finding what is missing:

    Code:
    if var == 5
        print("Hello, World!")
    Code:
    if (var == 5
    {
        print("Hello, World!")
    }
    In both cases, the block--the `suite' rule--itself is a valid sentence.

    Soma
    Last edited by phantomotap; 02-03-2015 at 08:23 PM.
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  15. #45
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    [Message]*blah* *blah* *grammar* *blah* *redefine* *blah* *blah* *blah*[/Message]
    O_o

    Really? Really?

    Yeah. Fine. You can rebuild the parser to change the grammatical binding of a character to a token.

    Let's do that now!

    Code:
    add_expr: term ('+' term)*
    // ...
    opr_expr: add_expr | sub_expr // many more
    // ...
    spl_stmt: (opr_expr | fcl_expr) ';'
    // ...
    grp_stmt: '{'  (spl_stmt)* '}'
    // ...
    cmpltyfngstupid_spl_stmt: ')' (opr_expr | fcl_expr) ';'
    // ...
    cmpltyfngstupid_grp_stmt: ')' '{'  (spl_stmt)* '}'
    // ...
    bnch_if: "if" '(' cnd_stmt cmpltyfngstupid_grp_stmt | cmpltyfngstupid_spl_stmt
    Code:
    if(true) printf("Hello, World!"); // good
    Code:
    if(true)
    {
        printf("Hello, World!"); // still good
    }
    Congratulations. The ')' character grammatical binds to the block.

    Let's style the code for semantics to match the grammar.

    Code:
    if(true
    ){
        printf("Hello, World!"); // still good
    }
    That's really ....... dumb and ridiculously ugly; go die in a fire.

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lisp Help
    By anirban in forum Tech Board
    Replies: 1
    Last Post: 01-15-2012, 04:14 PM
  2. Help on LISP please?
    By ssharish2005 in forum Tech Board
    Replies: 1
    Last Post: 02-08-2008, 10:12 AM
  3. Lisp
    By Silvercord in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 08-26-2003, 12:41 PM
  4. Lisp
    By MethodMan in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 11-18-2002, 04:41 PM
  5. Lisp
    By Lechugas in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 01-18-2002, 12:21 PM