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 8666505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:44:58+00:00 2026-06-12T17:44:58+00:00

(def tmp = [ 1 2 3 9 4 8]) I’m trying to create

  • 0
 (def tmp = [ 1 2 3 9 4 8])

I’m trying to create pairs of 2, then for each pair, subtract the second number from the first.
desired result: (1 6 4)

Here is what I was trying:

(map #(apply - %2 %1) (partition 2 tmp))

how can I do this?

  • 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-06-12T17:44:59+00:00Added an answer on June 12, 2026 at 5:44 pm

    Partition produces a sequence of sequences so the function you map over them needs to expect a sequence of two items. There are several ways to express this:

    (def tmp  [ 1 2 3 9 4 8])
    
    user> (map #(- (second %) (first %)) (partition-all 2 tmp ))
    (1 6 4)
    
    user> (map #(apply - (reverse %)) (partition-all 2 tmp ))
    (1 6 4)
    
    user> (map (fn [[small large]] (- large small)) (partition-all 2 tmp ))
    (1 6 4)
    

    The version using apply is different because it will still “work” on odd length lists:

    user> (map #(apply - (reverse %)) (partition-all 2 [1 2 3 4 5 6 7] ))
    (1 1 1 -7)
    

    The others will crash on invalid input, which you may prefer.

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

Sidebar

Related Questions

I'm trying to figure out how to dynamically create methods class MyClass def initialize(dynamic_methods)
Trying to create an IMGKit instance in one of my Rails controllers: def wkhtmltoimage
class Packagings: def _init_(self): self.length,self.deckle,self.tmp,self.flute,self.gsm,self.t_weight,self.weight def read_values(self): print Select Type Of Paper 1.3 Ply
The python implementation import sys def move(src, dst, tmp, num): if num == 1:
def partial(template, *args) options = args.extract_options! options.merge!(:layout => false) if collection = options.delete(:collection) then
In views.py def showfiledata(request): with open(/home/tazim/webexample/tmp.txt) as f: read_data = f.read() f.closed return_dict =
sockets map def: map<unsigned char[6],RawSocket> sockets_; set value to the sockets map: RawSocket tmp(ifcName,newSocketsIt->src_mac_);
class MyClass def test ... end end tmp = MyClass.new tmp.test do |t| here
/home/bar/foo/test.py: I am trying test.py to print /home/bar/foo irrespective of from where I run
How to generate compressed files on request. I have this controller def create send_data

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.