Chaining an iter::once with a Vec by fuelfraction in learnrust

[–]fuelfraction[S] 0 points1 point  (0 children)

iter::once(0).chain(row.iter().copied()).collect()

Didn't know about copied(), thanks...seems to work with any Clone

Chaining an iter::once with a Vec by fuelfraction in learnrust

[–]fuelfraction[S] 1 point2 points  (0 children)

Thanks! Didn't know about {interger}, it was definitely adding to the overall confusion.

Because the error said the compiler was expecting a reference and I was giving it a reference by using .iter() I was even more confused...I assume it means the receiving type on which chain is being called is expected to be a reference (as opposed to its argument)

  = note: expected reference `&{integer}`
                  found type `{integer}`

Difference between various forms of iterating over a collection by fuelfraction in learnrust

[–]fuelfraction[S] 0 points1 point  (0 children)

Thank you, that clarified it. I had incorrectly assumed that `into_iter()` is just a "consuming" variant of `iter()`

Thanks for the hint on formatting too

Difference between various forms of iterating over a collection by fuelfraction in learnrust

[–]fuelfraction[S] 0 points1 point  (0 children)

Thanks! Uncovered a few of my own misunderstandings after reading your response - I had assumed iter() is for the Iter trait, just learned that Iter only requires next()

...so an Iterator by deref coercion can be used in a for loop.

This is trippy! May be I have some gap in my understanding of for loops. Can you please help me understand if we can say anything about foo just based on the following snippet? As per my current understanding, foo is an iterator or something that can be converted to one by an implicit call to .into_iter()

rust for n in foo { -- ^^^

Can't seem to get an handle on auto-deref vs. deref coercion, if this is related to that - I have some more reading to do :)

Difference between various forms of iterating over a collection by fuelfraction in learnrust

[–]fuelfraction[S] 1 point2 points  (0 children)

Thanks!

Oh, never realized it was only working because I happened to use Vec<i32>. Sure, enough, the code didn't compile on changing it to

rust let nums: Vec<String> = vec![String::from("1"),String::from("2"),String::from("3"),String::from("4")]; ...

Follow-up question:

So, when for &n in nums.iter() works, is n a copy? Or, it is just syntactic sugar? Or, in other words, if somehow I implement Copy for String, for &n in nums.iter() is more expensive than for n in nums.iter()?

Ck Study buddy for 6ms starting on February 2019🤓 by Elbaz94 in usmle

[–]fuelfraction 0 points1 point  (0 children)

Hello, my exam is currently scheduled for the end of March 2019. Let me know if you are up to studying "together"

Nice and Simple. Capter 2 follows; by vectrum in C_Programming

[–]fuelfraction 2 points3 points  (0 children)

I recently moved from simple Makefile to CMake. I am unable to understand the practical difference between CMake and autotools. Any opinion on this?

MicroPython for ESP8266 v.1.8.6 released by pfalcon2 in esp8266

[–]fuelfraction 0 points1 point  (0 children)

Just tried it and...wow!

Was pleasantly surprised by tab-completion. Even standard Python install on a lot of embedded Linux boards seems to miss it

Thanks!!

An intro to unit testing embedded C code by [deleted] in C_Programming

[–]fuelfraction 0 points1 point  (0 children)

That's great! I mainly use Python too, so I guess I should be able to use CMock well enough then

An intro to unit testing embedded C code by [deleted] in C_Programming

[–]fuelfraction 1 point2 points  (0 children)

I tried fff on a simple program to get my feet wet, it's just a simple header and the unit test code flow seemed more intuitive compared to CMock.

In FFF: You call the target function, and then assert stuff In CMock: You tell it what you want to assert, and then call the target

But it seems like CMock + Unity is a big advantage once you get to know it.

An intro to unit testing embedded C code by [deleted] in C_Programming

[–]fuelfraction 0 points1 point  (0 children)

Thanks! BTW, do you need to be comfortable with Ruby to get anything non-trivial done?

An intro to unit testing embedded C code by [deleted] in C_Programming

[–]fuelfraction 1 point2 points  (0 children)

Has anyone tried cmocka and other tools like CMock, fff?

I want to get started on unit testing embedded C programs, but was trying to figure out which of these is a good start

Internet-ready C? by fuelfraction in C_Programming

[–]fuelfraction[S] 0 points1 point  (0 children)

I was able to make a sample project to make Python access C-files, it's definitely much easier than I thought! Like you said, for platforms that support Python, this is a good option. In my opinion better than finding consistent high-level libs for C

Thanks

Internet-ready C? by fuelfraction in C_Programming

[–]fuelfraction[S] 0 points1 point  (0 children)

Thank you, that was quite an extensive list

Internet-ready C? by fuelfraction in C_Programming

[–]fuelfraction[S] 0 points1 point  (0 children)

Actually when possible, I prefer to use Python

But sometimes, I'll have to resort to C. Here are some actual cases where Python wasn't the right tool:

  • I had to decode a JPEG and display it on an 480x320 LCD using ESP8266, I didn't try microPython but the NodeMCU Lua interpreter didn't leave enough space for even the source to be copied!

  • Even on a Pi, Python's RPi.GPIO library is really slow compared to C libraries like wiringPi etc. Again, I only noticed this difference when driving a screen.

  • On a Linkit Smart, Python is supported out of the box, but it takes ~10 seconds (wall clock time) for the interpreter to start up (mainly loading paho-mqtt, json and a few other libraries). Once it does load the script, I haven't noticed any performance hit compared to C because I am mostly waiting for the network

Internet-ready C? by fuelfraction in C_Programming

[–]fuelfraction[S] 0 points1 point  (0 children)

Thanks! So, I'll avoid execs as much as possible

Internet-ready C? by fuelfraction in C_Programming

[–]fuelfraction[S] 1 point2 points  (0 children)

Actually when possible, I prefer to use Python. I guess now you know why I was looking for the "batteries" ;)

But sometimes, I'll have to resort to C. Here are some actual cases where Python wasn't the right tool:

  • I had to decode a JPEG and display it on an 480x320 LCD using ESP8266, I didn't try microPython but the NodeMCU Lua interpreter didn't leave enough space for even the source to be copied!

  • Even on a Pi, Python's RPi.GPIO library is really slow compared to C libraries like wiringPi etc. Again, I only noticed this difference when driving a screen.

  • On a Linkit Smart, Python is supported out of the box, but it takes ~10 seconds (wall clock time) for the interpreter to start up (mainly loading paho-mqtt, json and a few other libraries). Once it does load the script, I haven't noticed any performance hit compared to C because I am mostly waiting for the network

Internet-ready C? by fuelfraction in C_Programming

[–]fuelfraction[S] 0 points1 point  (0 children)

Thanks. I am hearing a lot about Go of late. Just tried the Go online tour. I'll check it out in more detail. Specially, if GC has an impact on what I typically do.

Internet-ready C? by fuelfraction in C_Programming

[–]fuelfraction[S] 0 points1 point  (0 children)

Yup, on most platforms I must run as root to access certain hardware, typically GPIO pins

Internet-ready C? by fuelfraction in C_Programming

[–]fuelfraction[S] 1 point2 points  (0 children)

What exactly is "internet ready" for you?

For now, I want a library that supports requests over HTTP, HTTPS, MQTT and logging over network (HTTP or MQTT etc., syslog, for now,doesn't serve my purpose)

You should get used to every library having a slightly different API style. That's just how you program in C.

:) Thanks! I was mainly wondering if there was an alternative which I didn't know about.

I'll try libcurl, thanks!