Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

is this a pure function?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have one basic question, is function get-actor-by-id "pure" function?
 
Marshal
Posts: 5120
319
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From Wikipedia:

In computer programming, a function may be considered a pure function if both of the following statements about the function hold:

  • The function always evaluates the same result value given the same argument value(s). The function result value cannot depend on any hidden information or state that may change while program execution proceeds or between different executions of the program, nor can it depend on any external input from I/O devices
  • Evaluation of the result does not cause any semantically observable side effect or output, such as mutation of mutable objects or output to I/O devices


  • So, given those criteria would you say your function is 'pure'?
     
    Nenad Perivojevic
    Greenhorn
    Posts: 6
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I guess not, function result depends on database state in this case.
    Thanks.
     
    Tim Cooke
    Marshal
    Posts: 5120
    319
    IntelliJ IDE Python Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Exactly right. You're welcome.
     
    Rancher
    Posts: 357
    21
    Mac OS X Monad Clojure Linux
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    And just a brief note about naming conventions: You'll see ! at the end of functions that specifically change their environment (like swap! and reset! for atoms) and in clojure.java.jdbc, you'll see ! at the end of functions that (potentially) modify the database (like insert! and delete!). However, just as deref does not have ! even though an atom's value may change each time you dereference it, so clojure.java.jdbc's query function also does not have ! even though the database could be changing and the results be different on each call.
    reply
      Bookmark Topic Watch Topic
    • New Topic