Help in applescript

Discussion in 'Mac Programming' started by lagoon, Sep 22, 2011.

  1. lagoon macrumors newbie

    Joined:
    Sep 22, 2011
    #1
    I need help to set a variable in applescript to be able to change based on a result. I'm trying to make an algebra solver with applescript. Thanks for any help.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    This is a pretty basic AppleScript question. Are you using a book or following a tutorial or something? If not it might be a good idea. Anyway:

    Code:
    set variableName to 1
    
    would create/set a variable called variableName to the value 1.
     
  3. ytk macrumors regular

    Joined:
    Jul 8, 2010
    #3
    :eek: Do yourself a favor... don't.

    Unless you're doing system interaction, there's no good reason to use AppleScript for anything. Even then, you're probably better off using a language like Ruby or Python with an AppleScript bridge such as Appscript.

    AppleScript is an incredibly powerful and useful tool, hobbled by a language that's sheer misery to use. Between the confusing syntax, esoteric data typing rules, and random gotchas and reliability issues that tend to crop up with little or no explanation as to why, there's just no good reason to submit yourself to that kind of pain. And that's not even taking into account the performance, which can at best be described as middling.

    If you just want to learn the basics of AppleScript, that's fine. It's useful to know as a general matter, and it's pretty handy for banging out quick scripts to automate repetitive tasks—and far more powerful and flexible than Automator in that regard. But if you're trying to use it to solve actual problems that don't involve interacting with the system, turn back... for down that road lies madness.
     
  4. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #4
    Depending on what you mean by algebra solver, I have to agree with the previous poster. Apple script is meant to automate things, or adapt how things work to fit your needs. I don't think it's even possible to make an algebra solver with Applescript, unless you are merely thinking of shuffling data around to existing programs that do most of the actual work. First you would need to create a lexer and parser, parse the math expression, build an abstract syntax tree and formulate algebraic rules as a set of algorithms that can operate on the syntax tree and re-build/re-order it until you reach canonical form. :)

    http://www.math.wpi.edu/IQP/BVCalcHist/calc5.html
     
  5. ytk macrumors regular

    Joined:
    Jul 8, 2010
    #5
    Well, technically AppleScript is Turing complete, so it's possible. In much the same way that it's possible to ride across the country on a unicycle.
     
  6. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #6
    By all practical means, using conventional methods, no it isn't.
     
  7. ytk macrumors regular

    Joined:
    Jul 8, 2010
    #7
    Turing completeness: "[A programming language] is said to be Turing complete or computationally universal if and only if it can be used to simulate any single-taped Turing machine and thus in principle any computer."

    So AppleScript can, theoretically, be used to solve any problem that's solvable in any other programming language. And the proof that AppleScript is Turing complete is quite easy: You could use AppleScript to implement brainf*ck, a language that is known to be Turing complete.
     
  8. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #8
    Thanks for being dense on purpose. The task is closely related to creating you own programming language, the means you would use to do that is not available in applescript. That is the adequate, practical, realistic and sane answer. Moreover, something being theoretically possible does not equal humanly possible, for example implement Windows Vista (~50 million lines of code) with nothing but switches .
     
  9. ytk macrumors regular

    Joined:
    Jul 8, 2010
    #9
    "Impossible doesn't mean very difficult. Very difficult is winning the Nobel Prize. Impossible is eating the Sun."
    —Lou Reed, Penn & Teller's Smoke and Mirrors

    You said it was not possible. But it is indeed possible, just like (as I said above) it's possible to cross the country on a unicycle. The fact that it's an extremely labor-intensive and impractical waste of time which most sane people are unlikely to succeed at or even attempt has no bearing on its possibility.

    And anyway, just because YOU don't think you could do it doesn't make it impossible. :p
     
  10. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #10
    Yes, and I also explained (twice) my meaning. But you choose to ignore that and interpret it, literally. :D
     

Share This Page