{"title":"To nreverse when consing a list or by pointer manipulation, to avoid it; that is the question","authors":"R. Waters","doi":"10.1145/181889.181892","DOIUrl":null,"url":null,"abstract":"A situation that arises all the time in Lisp is the need to create a list of elements where the order of the elements in the list is the same as the order that they are created in time---i.e., the first element computed is the first element in the list, the second element computed is the second element in the list, etc. There are two basic ways of doing this: the nreverse approach and the rplacd approach. In the nreverse approach, you push the elements onto the list as they are computed and then use nreverse to put the list into the correct order after all of the elements have been computed. In the rplacd approach, you maintain a pointer to the end of the list and use rplacd to put each element directly into its proper place in the list.","PeriodicalId":262740,"journal":{"name":"ACM SIGPLAN Lisp Pointers","volume":"46 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"1993-10-01","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"0","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"ACM SIGPLAN Lisp Pointers","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1145/181889.181892","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 0
Abstract
A situation that arises all the time in Lisp is the need to create a list of elements where the order of the elements in the list is the same as the order that they are created in time---i.e., the first element computed is the first element in the list, the second element computed is the second element in the list, etc. There are two basic ways of doing this: the nreverse approach and the rplacd approach. In the nreverse approach, you push the elements onto the list as they are computed and then use nreverse to put the list into the correct order after all of the elements have been computed. In the rplacd approach, you maintain a pointer to the end of the list and use rplacd to put each element directly into its proper place in the list.