Skip to content

Guide macros and unsafe#16331

Merged
bors merged 2 commits into
rust-lang:masterfrom
steveklabnik:guide_macros_and_unsafe
Aug 21, 2014
Merged

Guide macros and unsafe#16331
bors merged 2 commits into
rust-lang:masterfrom
steveklabnik:guide_macros_and_unsafe

Conversation

@steveklabnik

Copy link
Copy Markdown
Contributor

The last two sections of the guide, and a small conclusion. I suck at conclusions.

I also realized I never covered strings, so I'm going to put that section up before we're actually 'done.'

Comment thread src/doc/guide.md Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/is is/is its

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dammmit, thank you

@steveklabnik

Copy link
Copy Markdown
Contributor Author

@jakub- see if the extra words i added fixes your issue about the mutex.

Comment thread src/doc/guide.md Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing *.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

@steveklabnik

Copy link
Copy Markdown
Contributor Author

@jakub- thanks, fixed!

Comment thread src/doc/guide.md Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is supposed to showcase the power of the macro system but it doesn't seem that way to me. It just looks like regex is implemented with macros rather than functions. With functions you could something like this where the returned structure has a function called is_match to test with.

let date_matcher = regex(r"^\d{4}-\d{2}-\d{2}$");
println!("{}", date_matcher.is_match("2014-01-01"));

Is it easy to show why it is much better implemented as a macro than a function? If so, this seems like a good place for it. Otherwise, the conclusion might be that it's another variant of a function but why should we care.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point is mostly to show that macros exist, but it is true that it would be good to mention why it is implemented this way.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussing println! might be a good example? It does relatively complicated computation (compared to a C-like macro anyway), e.g. parsing & processing "{foo:<5.8t} {0:03d}", x, foo = y, and results in something that has a clear benefit: compile-time-checked flexible format strings.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea, especially since it's the macro we've been using already, and doesn't assume knowledge of something else, like regular expressions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is assert! simple? It might be another alternative.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is an alternative, but it's not often used. At least, maybe assert_eq! or something would be better.

@steveklabnik

Copy link
Copy Markdown
Contributor Author

I've updated this PR to talk about println! instead of regexes. I like it better, but I'm unsure as to how much of a good idea it is to show the expanded output. I kinda like the shock-and-awe effect, heh.

Comment thread src/doc/guide.md Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/numer/number/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i really, really, really need to figure out how to get my spell checker to not throw errors in code blocks, it's how i keep missing things like this

@mdinger

mdinger commented Aug 12, 2014

Copy link
Copy Markdown
Contributor

Much better macro intro.
Before - it was: "Macros do cool things but I'm not gonna show any of them to you"
Now - it's: "Macros are cool. Check this out!"

@steveklabnik

Copy link
Copy Markdown
Contributor Author

@mdinger awesome 😄

@steveklabnik

Copy link
Copy Markdown
Contributor Author

@huonw do you have anything to say here? You reviewed the initial draft.

@huonw

huonw commented Aug 14, 2014

Copy link
Copy Markdown
Contributor

I'll try to look over it again in the next day or so.

@steveklabnik steveklabnik force-pushed the guide_macros_and_unsafe branch from 1664a97 to b23fd8d Compare August 20, 2014 18:43
@steveklabnik

Copy link
Copy Markdown
Contributor Author

@brson : I reabased this to fix the merge error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants