Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6023869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:04:12+00:00 2026-05-23T04:04:12+00:00

inspired by Clojure, and Peter Norvig I have been trying my hand at implementing

  • 0

inspired by Clojure, and Peter Norvig

I have been trying my hand at implementing a simple Lisp in obj-c. I have many of the basics (including some cool cocoa integration similar to Clojure) working and would like to move on to arithmetic.

A little background on how I have implemented this so far: I am using a tiny class “Scope”, which is just an NSMutableDictionary for local vars, with a pointer to a parent “Scope”. (AKA, I am constrained to only storing objects.)

I parse numbers with the following rule: a plain number like 2, or 2.7, gets converted to an [NSNumber numberWithIneger:] or [NSNumber numberWithDouble:]. But for cocoa integration you can also do things like 2i, or 4U, to create the NSNumber with a specific scalar type. (I also created a category around NSObject and made a new method performSelector:withObjects: that smartly unboxes the args, and boxes back up the return type to actually make this useful)

I have a special form that looks like: (static Math add: 1 2 3 4), which would turn into a obj-c method call that looks like: [Math add:args]

Given all this, my question to all of you fine folks is: what’s a good way to implement the “add:” method?

I was hoping to do something similar to how I believe clojure does (use to do?) it, by implementing a bunch of methods like add:(int)x to:(long)y, add:(long)x to:(float)y, etc, etc, through all possible combinations, and reducing over the args list pair-wise adding everything. But of course, obj-c doesn’t support overriding methods like that. Other than constraining myself to only addition on NSIntegers and doubles, is there any kind of trickery I can do to get where I want? I don’t even really care if it’s super efficient (though, that’s always a plus!)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:04:13+00:00Added an answer on May 23, 2026 at 4:04 am

    Easy method: simply turn all numbers into doubles when doing arithmetic, and ignore casting and precision issues.

    Another option is to use NSDecimalNumber instead of NSNumber everywhere. There’s the +[NSDecimalNumber decimalNumberWithString] method that you could use for boxing, and there are also methods for performing arithmetic with multiple NSDecimalNumbers. Of course, you have more overhead this way, but I imagine raw performance is not a primary concern.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Inspired by Raymond Chen's post , say you have a 4x4 two dimensional array,
Inspired by this question , I wanted to try my hand at the latest
After making some comments , I've been inspired to get some feedback on the
Okay, I've been inspired to do some head punching . Seems like overloading operator&
Trying to get a simple string replace to work using a Groovy script. Tried
Inspired by this CodingHorror article, Protecting Your Cookies: HttpOnly How do you set this
Inspired by the MVC storefront the latest project I'm working on is using extension
Inspired by another question asking about the missing Zip function: Why is there no
Inspired by this question and answer , how do I create a generic permutations
Inspired by the question What’s the simplest way to call Http GET url using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.