Trying to get this code to work, can't understand where to put the argument in and keep getting errorsHaving trouble with this racket code. I keep getting this error, but I'm not sure how to fix itScheme - defining a definitionPosition of minimum element in listAbstract List Functions in Racket/Schemecompare the length of two list and append in racketAppend two functions recursively with Racket?Iterative decompose-as-sum-of-squares in RacketScheme integer to stringScheme Difficulty Understanding output of my function 'concat lists' outputTrying to understanding recursion and why an error is occurringScheme - returning first n-elements of an array

What's the right way to purge recurrently with apt?

Strat tremolo bar has tightening issues

Why is the application of an oracle function not a measurement?

Why is the relationship between frequency and pitch exponential?

Why don’t airliners have temporary liveries?

Movie about a boy who was born old and grew young

Does an ice chest packed full of frozen food need ice?

Do simulator games use a realistic trajectory to get into orbit?

What are the peak hours for public transportation in Paris?

What are the words for people who cause trouble believing they know better?

How do photons get into the eyes?

Select items in a list that contain criteria #2

Can a user sell my software (MIT license) without modification?

Why is the past conditionel used here?

What do we gain with higher order logics?

Random Portfolios vs Efficient Frontier

Does the growth of home value benefit from compound interest?

Smooth switching between 12v batteries, with toggle switch

SF novella separating the dumb majority from the intelligent part of mankind

Turing patterns

What is the advantage of carrying a tripod and ND-filters when you could use image stacking instead?

Last survivors from different time periods living together

How to pass a regex when finding a directory path in bash?

What risks are there when you clear your cookies instead of logging off?



Trying to get this code to work, can't understand where to put the argument in and keep getting errors


Having trouble with this racket code. I keep getting this error, but I'm not sure how to fix itScheme - defining a definitionPosition of minimum element in listAbstract List Functions in Racket/Schemecompare the length of two list and append in racketAppend two functions recursively with Racket?Iterative decompose-as-sum-of-squares in RacketScheme integer to stringScheme Difficulty Understanding output of my function 'concat lists' outputTrying to understanding recursion and why an error is occurringScheme - returning first n-elements of an array






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















Define the function iota1(n, m) that takes positive integers n, m with n < m as input, and outputs the list (n,n+1,n+2,...,m)



I've tried switching the code around multiple times but cannot seem to get it to function and display a list the right way



(define (iota1 n m)
(if (eq? n 0)
'()
(append (iota1 (< n m) (+ n 1)) (list n))))









share|improve this question






























    1















    Define the function iota1(n, m) that takes positive integers n, m with n < m as input, and outputs the list (n,n+1,n+2,...,m)



    I've tried switching the code around multiple times but cannot seem to get it to function and display a list the right way



    (define (iota1 n m)
    (if (eq? n 0)
    '()
    (append (iota1 (< n m) (+ n 1)) (list n))))









    share|improve this question


























      1












      1








      1








      Define the function iota1(n, m) that takes positive integers n, m with n < m as input, and outputs the list (n,n+1,n+2,...,m)



      I've tried switching the code around multiple times but cannot seem to get it to function and display a list the right way



      (define (iota1 n m)
      (if (eq? n 0)
      '()
      (append (iota1 (< n m) (+ n 1)) (list n))))









      share|improve this question
















      Define the function iota1(n, m) that takes positive integers n, m with n < m as input, and outputs the list (n,n+1,n+2,...,m)



      I've tried switching the code around multiple times but cannot seem to get it to function and display a list the right way



      (define (iota1 n m)
      (if (eq? n 0)
      '()
      (append (iota1 (< n m) (+ n 1)) (list n))))






      racket






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 26 at 12:21









      GAD3R

      2,32011229




      2,32011229










      asked Mar 24 at 15:21









      detail8891detail8891

      61




      61






















          2 Answers
          2






          active

          oldest

          votes


















          2














          There's a few oddities to the code you provided, which I've formatted for readability:



          (define (iota1 n m)
          (if (eq? n 0)
          '()
          (append (iota (< n m) (+ n 1))
          (list n))))


          The first is that the expression (< n m) evaluates to a boolean value, depending on whether n is less than m or not. When you apply iota to (< n m) in the expression (iota (< n m) (+ n 1)), you are giving iota a boolean value for its first argument instead of a positive integer.



          Secondly, the use of append is strange here. When constructing a list in Racket, it's much more common to use the function cons, which takes as arguments a value, and a list, and returns a new list with the value added to the front. For example,



          (append '(3) (append '(4) (append '(5) '()))) ==> '(3 4 5)
          (cons 3 (cons 4 (cons 5 '()))) ==> '(3 4 5)


          It's a good idea to opt for using cons instead of append because it's simpler, and because it is faster, since cons does not traverse the entire list like append does.



          Since this sounds a bit like a homework problem, I'll leave you with a "code template" to help you find the answer:



          ; n : integer
          ; m : integer
          ; return value : list of integers
          (define (iota1 n m)
          (if (> n m) ; base case; no need to do work when n is greater than m
          ... ; value that goes at the end of the list
          (cons ... ; the value we want to add to the front of the list
          (iota1 ... ...)))) ; the call to iota, generating the rest of the list





          share|improve this answer























          • Thanks for the feedback and sorry for the late response but, the only problem I am having is that whenever I put in the second argument("value that goes at the end of the list") it comes back as "expects a real as 2nd argument, given (cons 3 '())", I have the rest of the program complete just not that part, what does it mean by looking for a real argument? I tried googling it but came up with nothing. Thanks again for the help!

            – detail8891
            Mar 30 at 0:32











          • It's referring to the contract real?, which returns true when given a real number. See docs.racket-lang.org/reference/… for more information

            – Michael MacLeod
            Mar 30 at 5:48


















          1














          Welcome to the racket world, my version is here:



          #lang racket

          (define (iota1 n m)
          (let loop ([loop_n n]
          [result_list '()])
          (if (<= loop_n m)
          (loop
          (add1 loop_n)
          (cons loop_n result_list))
          (reverse result_list))))





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55325304%2ftrying-to-get-this-code-to-work-cant-understand-where-to-put-the-argument-in-a%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            There's a few oddities to the code you provided, which I've formatted for readability:



            (define (iota1 n m)
            (if (eq? n 0)
            '()
            (append (iota (< n m) (+ n 1))
            (list n))))


            The first is that the expression (< n m) evaluates to a boolean value, depending on whether n is less than m or not. When you apply iota to (< n m) in the expression (iota (< n m) (+ n 1)), you are giving iota a boolean value for its first argument instead of a positive integer.



            Secondly, the use of append is strange here. When constructing a list in Racket, it's much more common to use the function cons, which takes as arguments a value, and a list, and returns a new list with the value added to the front. For example,



            (append '(3) (append '(4) (append '(5) '()))) ==> '(3 4 5)
            (cons 3 (cons 4 (cons 5 '()))) ==> '(3 4 5)


            It's a good idea to opt for using cons instead of append because it's simpler, and because it is faster, since cons does not traverse the entire list like append does.



            Since this sounds a bit like a homework problem, I'll leave you with a "code template" to help you find the answer:



            ; n : integer
            ; m : integer
            ; return value : list of integers
            (define (iota1 n m)
            (if (> n m) ; base case; no need to do work when n is greater than m
            ... ; value that goes at the end of the list
            (cons ... ; the value we want to add to the front of the list
            (iota1 ... ...)))) ; the call to iota, generating the rest of the list





            share|improve this answer























            • Thanks for the feedback and sorry for the late response but, the only problem I am having is that whenever I put in the second argument("value that goes at the end of the list") it comes back as "expects a real as 2nd argument, given (cons 3 '())", I have the rest of the program complete just not that part, what does it mean by looking for a real argument? I tried googling it but came up with nothing. Thanks again for the help!

              – detail8891
              Mar 30 at 0:32











            • It's referring to the contract real?, which returns true when given a real number. See docs.racket-lang.org/reference/… for more information

              – Michael MacLeod
              Mar 30 at 5:48















            2














            There's a few oddities to the code you provided, which I've formatted for readability:



            (define (iota1 n m)
            (if (eq? n 0)
            '()
            (append (iota (< n m) (+ n 1))
            (list n))))


            The first is that the expression (< n m) evaluates to a boolean value, depending on whether n is less than m or not. When you apply iota to (< n m) in the expression (iota (< n m) (+ n 1)), you are giving iota a boolean value for its first argument instead of a positive integer.



            Secondly, the use of append is strange here. When constructing a list in Racket, it's much more common to use the function cons, which takes as arguments a value, and a list, and returns a new list with the value added to the front. For example,



            (append '(3) (append '(4) (append '(5) '()))) ==> '(3 4 5)
            (cons 3 (cons 4 (cons 5 '()))) ==> '(3 4 5)


            It's a good idea to opt for using cons instead of append because it's simpler, and because it is faster, since cons does not traverse the entire list like append does.



            Since this sounds a bit like a homework problem, I'll leave you with a "code template" to help you find the answer:



            ; n : integer
            ; m : integer
            ; return value : list of integers
            (define (iota1 n m)
            (if (> n m) ; base case; no need to do work when n is greater than m
            ... ; value that goes at the end of the list
            (cons ... ; the value we want to add to the front of the list
            (iota1 ... ...)))) ; the call to iota, generating the rest of the list





            share|improve this answer























            • Thanks for the feedback and sorry for the late response but, the only problem I am having is that whenever I put in the second argument("value that goes at the end of the list") it comes back as "expects a real as 2nd argument, given (cons 3 '())", I have the rest of the program complete just not that part, what does it mean by looking for a real argument? I tried googling it but came up with nothing. Thanks again for the help!

              – detail8891
              Mar 30 at 0:32











            • It's referring to the contract real?, which returns true when given a real number. See docs.racket-lang.org/reference/… for more information

              – Michael MacLeod
              Mar 30 at 5:48













            2












            2








            2







            There's a few oddities to the code you provided, which I've formatted for readability:



            (define (iota1 n m)
            (if (eq? n 0)
            '()
            (append (iota (< n m) (+ n 1))
            (list n))))


            The first is that the expression (< n m) evaluates to a boolean value, depending on whether n is less than m or not. When you apply iota to (< n m) in the expression (iota (< n m) (+ n 1)), you are giving iota a boolean value for its first argument instead of a positive integer.



            Secondly, the use of append is strange here. When constructing a list in Racket, it's much more common to use the function cons, which takes as arguments a value, and a list, and returns a new list with the value added to the front. For example,



            (append '(3) (append '(4) (append '(5) '()))) ==> '(3 4 5)
            (cons 3 (cons 4 (cons 5 '()))) ==> '(3 4 5)


            It's a good idea to opt for using cons instead of append because it's simpler, and because it is faster, since cons does not traverse the entire list like append does.



            Since this sounds a bit like a homework problem, I'll leave you with a "code template" to help you find the answer:



            ; n : integer
            ; m : integer
            ; return value : list of integers
            (define (iota1 n m)
            (if (> n m) ; base case; no need to do work when n is greater than m
            ... ; value that goes at the end of the list
            (cons ... ; the value we want to add to the front of the list
            (iota1 ... ...)))) ; the call to iota, generating the rest of the list





            share|improve this answer













            There's a few oddities to the code you provided, which I've formatted for readability:



            (define (iota1 n m)
            (if (eq? n 0)
            '()
            (append (iota (< n m) (+ n 1))
            (list n))))


            The first is that the expression (< n m) evaluates to a boolean value, depending on whether n is less than m or not. When you apply iota to (< n m) in the expression (iota (< n m) (+ n 1)), you are giving iota a boolean value for its first argument instead of a positive integer.



            Secondly, the use of append is strange here. When constructing a list in Racket, it's much more common to use the function cons, which takes as arguments a value, and a list, and returns a new list with the value added to the front. For example,



            (append '(3) (append '(4) (append '(5) '()))) ==> '(3 4 5)
            (cons 3 (cons 4 (cons 5 '()))) ==> '(3 4 5)


            It's a good idea to opt for using cons instead of append because it's simpler, and because it is faster, since cons does not traverse the entire list like append does.



            Since this sounds a bit like a homework problem, I'll leave you with a "code template" to help you find the answer:



            ; n : integer
            ; m : integer
            ; return value : list of integers
            (define (iota1 n m)
            (if (> n m) ; base case; no need to do work when n is greater than m
            ... ; value that goes at the end of the list
            (cons ... ; the value we want to add to the front of the list
            (iota1 ... ...)))) ; the call to iota, generating the rest of the list






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 24 at 19:11









            Michael MacLeodMichael MacLeod

            6016




            6016












            • Thanks for the feedback and sorry for the late response but, the only problem I am having is that whenever I put in the second argument("value that goes at the end of the list") it comes back as "expects a real as 2nd argument, given (cons 3 '())", I have the rest of the program complete just not that part, what does it mean by looking for a real argument? I tried googling it but came up with nothing. Thanks again for the help!

              – detail8891
              Mar 30 at 0:32











            • It's referring to the contract real?, which returns true when given a real number. See docs.racket-lang.org/reference/… for more information

              – Michael MacLeod
              Mar 30 at 5:48

















            • Thanks for the feedback and sorry for the late response but, the only problem I am having is that whenever I put in the second argument("value that goes at the end of the list") it comes back as "expects a real as 2nd argument, given (cons 3 '())", I have the rest of the program complete just not that part, what does it mean by looking for a real argument? I tried googling it but came up with nothing. Thanks again for the help!

              – detail8891
              Mar 30 at 0:32











            • It's referring to the contract real?, which returns true when given a real number. See docs.racket-lang.org/reference/… for more information

              – Michael MacLeod
              Mar 30 at 5:48
















            Thanks for the feedback and sorry for the late response but, the only problem I am having is that whenever I put in the second argument("value that goes at the end of the list") it comes back as "expects a real as 2nd argument, given (cons 3 '())", I have the rest of the program complete just not that part, what does it mean by looking for a real argument? I tried googling it but came up with nothing. Thanks again for the help!

            – detail8891
            Mar 30 at 0:32





            Thanks for the feedback and sorry for the late response but, the only problem I am having is that whenever I put in the second argument("value that goes at the end of the list") it comes back as "expects a real as 2nd argument, given (cons 3 '())", I have the rest of the program complete just not that part, what does it mean by looking for a real argument? I tried googling it but came up with nothing. Thanks again for the help!

            – detail8891
            Mar 30 at 0:32













            It's referring to the contract real?, which returns true when given a real number. See docs.racket-lang.org/reference/… for more information

            – Michael MacLeod
            Mar 30 at 5:48





            It's referring to the contract real?, which returns true when given a real number. See docs.racket-lang.org/reference/… for more information

            – Michael MacLeod
            Mar 30 at 5:48













            1














            Welcome to the racket world, my version is here:



            #lang racket

            (define (iota1 n m)
            (let loop ([loop_n n]
            [result_list '()])
            (if (<= loop_n m)
            (loop
            (add1 loop_n)
            (cons loop_n result_list))
            (reverse result_list))))





            share|improve this answer



























              1














              Welcome to the racket world, my version is here:



              #lang racket

              (define (iota1 n m)
              (let loop ([loop_n n]
              [result_list '()])
              (if (<= loop_n m)
              (loop
              (add1 loop_n)
              (cons loop_n result_list))
              (reverse result_list))))





              share|improve this answer

























                1












                1








                1







                Welcome to the racket world, my version is here:



                #lang racket

                (define (iota1 n m)
                (let loop ([loop_n n]
                [result_list '()])
                (if (<= loop_n m)
                (loop
                (add1 loop_n)
                (cons loop_n result_list))
                (reverse result_list))))





                share|improve this answer













                Welcome to the racket world, my version is here:



                #lang racket

                (define (iota1 n m)
                (let loop ([loop_n n]
                [result_list '()])
                (if (<= loop_n m)
                (loop
                (add1 loop_n)
                (cons loop_n result_list))
                (reverse result_list))))






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 26 at 7:13









                simmonesimmone

                274110




                274110



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55325304%2ftrying-to-get-this-code-to-work-cant-understand-where-to-put-the-argument-in-a%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현