iota

Writing powers of 10 as constants compactly

纵然是瞬间 提交于 2019-12-18 04:52:48
问题 I'm reading the recently released The Go Programming Language, and it's been a joy so far (with Brian Kernighan being one of the authors, I wouldn't expect anything other than excellence anyway). I've came across the following exercise on chapter 3: Exercise 3.13 Write const declarations for KB, MB, up through YB as compactly as you can. ( NOTE : in this context, KB, MB, etc, denote powers of 1000) This is preceded by a section where iota is introduced as a useful constants generator

Implementing Iota in Haskell

我只是一个虾纸丫 提交于 2019-12-03 12:49:27
Iota is a ridiculously small "programming language" using only one combinator. I'm interested in understanding how it works, but it would be helpful to see the implementation in a language I'm familiar with. I found an implementation of the Iota programming language written in Scheme. I've been having a little trouble translating it to Haskell though. It's rather simple, but I'm relatively new to both Haskell and Scheme. How would you write an equivalent Iota implementation in Haskell? (let iota () (if (eq? #\* (read-char)) ((iota)(iota)) (lambda (c) ((c (lambda (x) (lambda (y) (lambda (z) ((x

Writing powers of 10 as constants compactly

亡梦爱人 提交于 2019-11-29 07:20:12
I'm reading the recently released The Go Programming Language , and it's been a joy so far (with Brian Kernighan being one of the authors, I wouldn't expect anything other than excellence anyway). I've came across the following exercise on chapter 3: Exercise 3.13 Write const declarations for KB, MB, up through YB as compactly as you can. ( NOTE : in this context, KB, MB, etc, denote powers of 1000) This is preceded by a section where iota is introduced as a useful constants generator mechanism; in particular, the previous paragraph shows a nice and compact way to define the powers of 1024 as

Set std::vector<int> to a range

不想你离开。 提交于 2019-11-29 06:06:24
问题 What's the best way for setting an std::vector<int> to a range, e.g. all numbers between 3 and 16? 回答1: You could use std::iota if you have C++11 support or are using the STL: std::vector<int> v(14); std::iota(v.begin(), v.end(), 3); or implement your own if not. If you can use boost , then a nice option is boost::irange: std::vector<int> v; boost::push_back(v, boost::irange(3, 17)); 回答2: std::vector<int> myVec; for( int i = 3; i <= 16; i++ ) myVec.push_back( i ); 回答3: See e.g. this question