porges
(match
(list (> x y) (stringp foo) (oddp n))
[(list #t _ #t ) (whatever)]
[(list _ #t _ ) (other-thing)]
[(list #t #f _ ) (etc)])
... or is that the joke :)C# has the ability to opt-into default checked arithmetic. I don't know of anyone that uses it...
Also, not every ‘ae’ was an ‘æ’—‘aerial’ is one example. I think the test is whether or not the Greek word used ‘αι’.
These samples do not appear in the paper, so we don't know what they saw.
The “iterators” discussed are Java-/C#-style iterators, not C++ ones (as I expected reading the abstract).
In a C++ context I would have expected lambdas vs iterators to be something like:
// lambda
float retVal = 0;
std::for_each(mb.cbegin(), mb.cend(), [&](item x) { retVal += item.price; });
return retVal;
// pure iterator
float retVal = 0;
for (auto it = mb.cbegin(); it != mb.cend(); ++it)
{
retVal += it->price;
}
return retVal;
... and the first would be better off as: return std::accumulate(mb.cbegin(), mb.cend(), 0f,
[](float acc, item x) { return acc + x.price; });
I think the need to use ref-capture (since you only get a side-effecting `std::function` to play with in their sample) would be the thing most likely to throw people off – as it’s something that should be avoided in most code, anyway ;)𝌆𝌇𝌉𝌊𝌏𝌐𝌒𝌓𝌡𝌢𝌤𝌥𝌪𝌫𝌭𝌮
So Unicode has Bagua (3 bits), Tài Xuán Jīng (4 trits), and I Ching (6 bits, but incomplete).
std::size is in C++17: http://en.cppreference.com/w/cpp/iterator/size
In fact, you can find the server stats from back then: http://web.archive.org/web/19970822145424/http://www.bath.ac...
This says that it transferred "3 599 Mbytes" and there were "728 506" requests. Interpreting "3 599" as 3.599 gives 4.94 bytes per request, which is absurd. It must be 3.6 GB, making each response just under 5 kB. This seems much more reasonable.
So the number on that page should probably be interpreted as 63 GB, which is reasonable if we assume the site became more popular later in the year, as the original source suggests (3.6 GB*12 = 43.2 GB, and the stats are from May).
Also notice the following year (1998) says 126 MBytes and in 1999, 197 GB. That's an order of magnitude jump!
{-# LANGUAGE PatternSynonyms, ViewPatterns #-}
pattern Even <- ((`mod` 2) -> 0)
pattern Odd <- ((`mod` 2) -> 1)
testNumber x = show x ++
case x of
Even -> " is even"
Odd -> " is odd"
data Color = Color { r :: Int, g :: Int, b :: Int }
pattern RGB r g b = Color r g b
-- NB: this is bidirectional automatically
printRGB :: Color -> IO ()
printRGB (RGB r g b) = print $ "Red: " ++ show r ++ " Green: " ++ show g ++ " Blue: " ++ show b
-- pretend we have functions to and from RGB and HSV representation
toHSV :: Color -> (Int, Int, Int)
toHSV = undefined -- implement this yourself!
fromHSV :: Int -> Int -> Int -> Color
fromHSV = undefined
pattern HSV h' s' v' <- (toHSV -> (h', s', v'))
-- here we explicitly provide an inversion
where HSV = fromHSV
printHSV :: Color -> IO ()
printHSV (HSV h s v) = print $ "Hue: " ++ show h ++ " Saturation: " ++ show s ++ " Value: " ++ show v
-- demonstrating being able to use pattern
-- to construct a value
addHue :: Int -> Color -> Color
addHue n (HSV h s v) = HSV (h + n) s vIf overflow is defined to wrap around then it's potentially an infinite loop (take N == MAXVALUE). With overflow defined as UB you can say the loop executes exactly N times (because you're not allowed to write code that overflows).
So UB is both bad and a source of power :)
It's actually reasonably easy to avoid the unnecessary copying.
Something like this would do (use a string as the buffer, pass it by reference, then use `try_emplace`). Also, it should probably be using the same hash function as your C code:
#include <cstdint>
#include <fstream>
#include <string>
#include <unordered_map>
class Intern_pool
{
struct fvn_hash
{
// FVN-1a hash -- http://isthe.com/chongo/tech/comp/fnv/
std::size_t operator()(const std::string& s) const
{
std::size_t hash = 2166136261; // offset basis (32 bits)
for (auto c : s)
{
hash ^= c; // xor
hash *= 16777619; // prime (32 bits)
}
return hash;
}
};
std::unordered_map<std::string, std::uint32_t, fvn_hash> map;
std::uint32_t next = 0;
public:
std::uint32_t add(const std::string& s)
{
auto r = map.try_emplace(s, next);
if (r.second)
{
++next;
}
return r.first->second;
}
};
int main(int argc, const char* argv[])
{
for (int i = 1; i < argc; ++i)
{
std::ifstream file(argv[i]);
Intern_pool intern_pool;
std::string line;
while (std::getline(file, line))
{
intern_pool.add(line);
}
}
return 0;
} 1
+---
V | V
Pa | Pa
V^-1 Pa^-1
+--------------- +-----
mA | mA/V mA/Pa | mA
kg/s | kg/V/s kg/Pa/s | kg/s
I can imagine a system that types this quite well.